Skip to main content

12. Symmetric Tree

easyAsked at Reddit

Determine if a binary tree is a mirror image of itself. Reddit asks this to gauge whether candidates can write paired-pointer recursion — the same skill needed when comparing two views of a comment tree (live vs. cached).

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Reddit loops.

  • Glassdoor (2026-Q1)Reddit comments-platform phone screen.

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

Input
root = [1,2,2,3,4,4,3]
Output
true

Example 2

Input
root = [1,2,2,null,3,null,3]
Output
false

Approaches

1. Inorder traversal and check palindrome

Inorder-traverse, check if the resulting array is a palindrome.

Time
O(n)
Space
O(n)
function isSymmetric(root) {
  const vals = [];
  function inorder(n) {
    if (!n) { vals.push(null); return; }
    inorder(n.left); vals.push(n.val); inorder(n.right);
  }
  inorder(root);
  for (let i = 0, j = vals.length - 1; i < j; i++, j--) {
    if (vals[i] !== vals[j]) return false;
  }
  return true;
}

Tradeoff: Works but allocates a full traversal array. Subtle: null markers needed or {1,2,2,null,3,null,3} appears symmetric.

2. Paired recursion (optimal)

Compare left.left to right.right and left.right to right.left recursively.

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 mirror(root.left, root.right);
}

Tradeoff: Clean, recursive, short-circuiting. The structural check (one null + one non-null) is crucial.

Reddit-specific tips

Reddit grades on the paired-recursion insight: you call mirror(left.left, right.right) and mirror(left.right, right.left). Many candidates try to compare left and right as a unit and confuse themselves.

Common mistakes

  • Forgetting to check structural equality (null vs non-null) — leads to comparing values on null nodes.
  • Calling mirror(left, right) on the same children: mirror(L.left, R.left) instead of mirror(L.left, R.right).
  • Iterative version: forgetting to push pairs of pointers (left-from-left, right-from-right).

Follow-up questions

An interviewer at Reddit may pivot to one of these next:

  • Iterative version using a queue of pairs.
  • Same tree (LC 100) — the simpler cousin.
  • Invert binary tree (LC 226) — related transformation.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why mirror(left.left, right.right)?

Symmetry means the leftmost of the left subtree mirrors the rightmost of the right subtree. The recursion encodes that geometric flip.

Can this be iterative?

Yes — use a queue, push pairs (left, right). Pop two at a time and check, then push (L.left, R.right) and (L.right, R.left).

Practice these live with InterviewChamp.AI

Drill Symmetric Tree and other Reddit interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →