11. Symmetric Tree
easyAsked at VercelGiven a binary tree, check if it is a mirror of itself (symmetric around its center). Vercel asks this because the recursive mirror-comparison shape shows up in their A/B route-mirror experiments.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Vercel loops.
- Glassdoor (2025-Q4)— Vercel screen recursion warm-up.
- Blind (2026-Q1)— Mentioned in Vercel onsite recap as a quick tree question.
Problem
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Constraints
The number of nodes in the tree is in the range [1, 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 traversal + palindrome check
Inorder traverse, then check the resulting array is a palindrome.
- Time
- O(n)
- Space
- O(n)
function isSymmetric(root) {
// Caveat: nulls must be encoded to distinguish [1,2,null] from [1,null,2].
const arr = [];
function dfs(n) { if (!n) { arr.push(null); return; } dfs(n.left); arr.push(n.val); dfs(n.right); }
dfs(root);
// palindrome check on arr...
}Tradeoff: Tricky to get null-encoding right; the recursive mirror is cleaner.
2. Recursive mirror comparison (optimal)
Helper compares (left, right). Both null → true. One null → false. Values equal AND left.left mirrors right.right AND left.right mirrors right.left.
- Time
- O(n)
- Space
- O(h)
function isSymmetric(root) {
function mirror(a, b) {
if (!a && !b) return true;
if (!a || !b) return false;
return a.val === b.val
&& mirror(a.left, b.right)
&& mirror(a.right, b.left);
}
return mirror(root.left, root.right);
}Tradeoff: The mirror pattern (left.left vs right.right, left.right vs right.left) is the whole trick. Articulate it explicitly.
Vercel-specific tips
Vercel wants you to articulate the mirror pattern out loud BEFORE coding: outer-vs-outer, inner-vs-inner. Bonus signal: offering the iterative BFS version with a queue of pairs as an alternative.
Common mistakes
- Comparing left.left to right.left — that's structural identity, not mirror.
- Forgetting the null pair check — crashes on mid-tree nulls.
- Treating an empty tree as not symmetric — empty IS symmetric; check the constraints.
Follow-up questions
An interviewer at Vercel may pivot to one of these next:
- Iterative version using a queue of (left, right) pairs.
- Invert a binary tree (LC 226) — related shape.
- Symmetric N-ary tree — generalize the mirror to k children.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why outer-vs-outer and inner-vs-inner?
Mirroring means the leftmost descendant on the left subtree should match the rightmost descendant on the right subtree. That's left.left vs right.right (outer) and left.right vs right.left (inner).
Can I solve this iteratively?
Yes — enqueue (root.left, root.right) and process pairs. Same logic in BFS form. Useful if recursion depth is a worry.
Practice these live with InterviewChamp.AI
Drill Symmetric Tree and other Vercel interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →