DSA interview question
A logo-design tool builds shapes as binary trees and flags designs that are mirror-symmetric around the vertical axis through the root. A tree is symmetric when its left subtree is a mirror image of its right subtree. Two trees mirror each other when their roots are equal, the first tree's left mirrors the second tree's right, and the first tree's right mirrors the second's left. It's the "identical trees" recursion with the children crossed.
Example: [1, 2, 2, 3, 4, 4, 3] → true; [1, 2, 2, null, 3, null, 3] → false.
bool isSymmetric(TreeNode* root);
| Input (level order) | Output | Explanation |
|---|---|---|
[1, 2, 2, 3, 4, 4, 3] | true | |
[1, 2, 2, null, 3, null, 3] | false | Both 3s hang on the right |
[1, 2, 2, 2, null, 2] | false | Values match but the shape doesn't |
[1] | true | |
[] | true |
(Confirm: both values and structure must mirror; an empty tree is symmetric.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in