11. Symmetric Tree
easyAsked at PayPalDecide whether a binary tree is a mirror of itself. PayPal uses this as a recursion check — testing whether you can write a helper that compares two trees with mirrored axes, the same pattern they use for symmetric-link reconciliation between buyer-side and seller-side transaction graphs.
By Alex Chen, 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.
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. 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.
Practice these live with InterviewChamp.AI
Drill Symmetric Tree and other PayPal interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →