11. Symmetric Tree
easyAsked at SnowflakeDetermine whether a binary tree is a mirror of itself around its center. Snowflake asks this to test paired-pointer recursion — the same pattern used to check tree balance invariants in their on-disk index structures.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Snowflake loops.
- Glassdoor (2025-Q4)— Snowflake new-grad onsite as recursion warm-up.
- LeetCode Discuss (2025-09)— Reported at Snowflake SDE-I screens.
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. Serialize left and right and compare
Serialize left subtree in-order and right subtree reverse-in-order; compare strings.
- Time
- O(n)
- Space
- O(n)
function isSymmetric(root) {
function ser(n, fwd) {
if (!n) return '#';
return fwd
? `${n.val},${ser(n.left, fwd)},${ser(n.right, fwd)}`
: `${n.val},${ser(n.right, fwd)},${ser(n.left, fwd)}`;
}
if (!root) return true;
return ser(root.left, true) === ser(root.right, false);
}Tradeoff: Works but O(n) space for serialization. Mention as a fallback only.
2. Paired-pointer recursion (optimal)
Define helper mirror(a, b): both null -> true; one null -> false; values differ -> false; otherwise recurse on (a.left, b.right) and (a.right, b.left).
- Time
- O(n)
- Space
- O(h)
function isSymmetric(root) {
function mirror(a, b) {
if (!a && !b) return true;
if (!a || !b) return false;
if (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: Linear, short-circuits on first mismatch. The two-pointer-into-one-tree pattern is reusable for many tree-equality problems.
Snowflake-specific tips
Snowflake interviewers grade this on whether you spot the 'two pointers into one tree' pattern and write the helper, instead of trying to do it with one pointer plus a global. Bonus signal: write the iterative version using a queue of (a, b) pairs, since recursion can blow the stack on adversarial 1000-node skewed inputs.
Common mistakes
- Comparing (a.left, b.left) and (a.right, b.right) — that's same-tree, not mirror.
- Forgetting the (one null, one not) case — both nulls is fine, both non-null is fine, but mismatched returns false.
- Recursing into root with a single pointer instead of pairing left and right subtrees.
Follow-up questions
An interviewer at Snowflake may pivot to one of these next:
- Iterative version with a queue.
- Find the largest symmetric subtree.
- Is the tree balanced (LC 110)?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why pair (a.left, b.right) and (a.right, b.left)?
Mirroring swaps left and right. So a's left should mirror b's right, and a's right should mirror b's left.
Can I solve this iteratively?
Yes — use a queue and push pairs (a, b). At each step pop a pair and apply the same checks. This is what you'd actually ship if recursion depth is a concern.
Practice these live with InterviewChamp.AI
Drill Symmetric Tree and other Snowflake interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →