Skip to main content

11. Symmetric Tree

easyAsked at Activision

Determine whether a binary tree is a mirror of itself — Activision uses this to gauge recursion fluency before pivoting to matchmaking-bracket trees.

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

Problem

Given the root of a binary tree, check whether it is a mirror of itself (symmetric around its center). Return true if the left subtree is a mirror reflection of the right subtree.

Constraints

  • Node count in 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. Brute force serialize

Serialize left and reversed right; compare strings.

Time
O(n)
Space
O(n)
function isSym(root) {
  const l = serialize(root.left);
  const r = serializeReversed(root.right);
  return l === r;
}

Tradeoff:

2. Recursive mirror check

Recurse on (left.left, right.right) and (left.right, right.left) — values must match at every step.

Time
O(n)
Space
O(h)
function isSymmetric(root) {
  const 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:

Activision-specific tips

Activision watches whether you reason about the symmetry invariant cleanly — the same mental model maps to mirrored matchmaking brackets and balanced lobby trees.

Solve it now

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

Output

Press Run or Cmd+Enter to execute

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →