11. Symmetric Tree
easyAsked at PayPalCheck if a binary tree reads identically when reflected around its root — values AND shape. PayPal candidates report this easy as a recursion litmus test: the single-argument recursion most people reach for cannot express the mirror constraint, so the graded move is introducing a two-argument helper that walks the two subtrees with crossed axes — the same compare-two-structures-in-parallel pattern behind reconciling buyer-side and seller-side views of one transaction.
By Sam K., Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in PayPal loops.
- Glassdoor (2025-11)— PayPal SDE-1 phone screen — mirroring helper expected.
- LeetCode (2026)— Problem #101 'Symmetric Tree' — canonical statement, bounds, and the iterative follow-up.
Problem
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). A tree is symmetric when its left subtree is the mirror reflection of its right subtree — equal values, with left and right children swapped at every level.
Constraints
The number of nodes in the tree is in the range [1, 1000].-100 <= Node.val <= 100Values alone cannot prove symmetry — the SHAPE must mirror too, which is why null positions matter in every comparison.
Examples
Example 1
root = [1,2,2,3,4,4,3]trueExplanation: Fold the tree down the center line: 2 faces 2, 3 faces 3, 4 faces 4 — both values and positions reflect, so the tree is symmetric.
Example 2
root = [1,2,2,null,3,null,3]falseExplanation: Both 2-nodes have a null LEFT child and a 3 on the right — identical subtrees, but not mirrored ones. This is the case that catches same-tree-style recursion.
Approaches
1. BFS level compare
BFS by level. At each level, the list of values should read the same forward and reversed.
- Time
- O(n)
- Space
- O(n)
function isSymmetric(root) {
let q = [root];
while (q.length) {
const vals = q.map(n => n ? n.val : null);
for (let i = 0, j = vals.length - 1; i < j; i++, j--) {
if (vals[i] !== vals[j]) return false;
}
q = q.flatMap(n => n ? [n.left, n.right] : []);
}
return true;
}Tradeoff: Conceptually clean but allocates level-arrays. Less elegant than recursive.
2. Recursive mirror helper (optimal)
Helper mirror(a, b). Both null → true. One null → false. Else a.val == b.val && mirror(a.left, b.right) && mirror(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;
return a.val === b.val
&& mirror(a.left, b.right)
&& mirror(a.right, b.left);
}
return !root || mirror(root.left, root.right);
}Tradeoff: The mirrored recursion (left vs right, right vs left) is the key trick. PayPal looks for this exact shape.
PayPal-specific tips
PayPal's grading rubric here is: did you introduce the two-argument helper? Without it, single-argument recursion can't express the mirror constraint. Bonus signal: mention that this exact two-arg-helper pattern is how PayPal validates buyer-side vs seller-side ledger trees match in mirror across a payment.
Common mistakes
- Trying to do it with a single-argument helper — can't express mirror without comparing two subtrees in parallel.
- Mirror calls left-left, right-right (same-tree pattern) — that's Same Tree, not Symmetric.
- Forgetting the both-null base case at the top.
Follow-up questions
An interviewer at PayPal may pivot to one of these next:
- Same Tree (LC 100).
- Invert Binary Tree (LC 226) — same mirror primitive applied to a single tree.
- Generalize to k-ary trees.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why mirror(a.left, b.right)?
Symmetry around the center means a's left subtree mirrors b's right subtree, and vice versa. You're crossing the axis.
Iterative version?
Push pairs of nodes onto a queue: (root.left, root.right). Pop pair, compare, then enqueue (left.left, right.right) and (left.right, right.left). Same crossing-the-axis pattern.
How is this different from Same Tree (LC 100)?
Same Tree compares two trees position-for-position: left vs left, right vs right. Symmetric Tree compares one tree against its own reflection, so every comparison crosses the axis: left vs right. The helper bodies look nearly identical — the argument crossing is the entire difference.