Skip to main content

11. Symmetric Tree

easyAsked at Zoom

Determine if a binary tree is a mirror of itself.

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). The left subtree must be a mirror reflection of the right subtree.

Constraints

  • 1 <= nodes <= 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 check

Inorder list must be a palindrome (broken for duplicate values).

Time
O(n)
Space
O(n)
const a=inorder(root); for(let i=0,j=a.length-1;i<j;i++,j--) if(a[i]!==a[j]) return false; return true;

Tradeoff:

2. Paired recursion

Compare the left child of one side with the right child of the other.

Time
O(n)
Space
O(h)
function isSymmetric(root) {
  function mirror(a, b) {
    if (!a && !b) return true;
    if (!a || !b || 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:

Zoom-specific tips

Zoom asks mirror-tree variants when probing for gallery-view layout reasoning where left/right participant tiles must mirror across screen-share splits — frame your answer in layout terms.

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 Zoom interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →