11. Symmetric Tree
easyAsked at ZoomDetermine if a binary tree is a mirror of itself.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given the root of a binary tree, check whether it is a mirror of itself (symmetric around its center). The left subtree must be a mirror reflection of the right subtree.
Constraints
1 <= nodes <= 1000-100 <= Node.val <= 100
Examples
Example 1
root=[1,2,2,3,4,4,3]trueExample 2
root=[1,2,2,null,3,null,3]falseApproaches
1. Inorder check
Inorder list must be a palindrome (broken for duplicate values).
- Time
- O(n)
- Space
- O(n)
const a=inorder(root); for(let i=0,j=a.length-1;i<j;i++,j--) if(a[i]!==a[j]) return false; return true;Tradeoff:
2. Paired recursion
Compare the left child of one side with the right child of the other.
- Time
- O(n)
- Space
- O(h)
function isSymmetric(root) {
function mirror(a, b) {
if (!a && !b) return true;
if (!a || !b || a.val !== b.val) return false;
return mirror(a.left, b.right) && mirror(a.right, b.left);
}
return !root || mirror(root.left, root.right);
}Tradeoff:
Zoom-specific tips
Zoom asks mirror-tree variants when probing for gallery-view layout reasoning where left/right participant tiles must mirror across screen-share splits — frame your answer in layout terms.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Symmetric Tree and other Zoom interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →