Check Whether a Reaction Tree Is a Mirror Image of Itself
Last updated: November 29, 2026
Quick Overview
Given the root of a binary tree, return whether the tree is symmetric around its center, meaning the left subtree is a mirror reflection of the right subtree.
Meta
November 29, 20260
0
0 solved
Given the root of a binary tree, return whether the tree is symmetric around its center, meaning the left subtree is a mirror reflection of the right subtree.
A quick binary tree warm-up in Meta phone screens. The interviewer checks that you compare the outer and inner pairs correctly and can give both a recursive and an iterative queue-based version.
What the Interviewer Expects
- Compare two subtrees in mirrored order
- Check outer pairs (left.left, right.right) and inner pairs (left.right, right.left)
- Handle None nodes cleanly
- Offer an iterative version with a queue of pairs
- State O(n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you write it without recursion?
- How would you check if two different trees are mirrors of each other?
- What if the tree is very deep and skewed?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is the root of a binary tree, possibly None. Return True if the tree looks the same when reflected across a vertical line through the root, comparing both shape and values. An empty tree is symm...
High-Level Design
A tree is symmetric when its two subtrees are mirrors. Two nodes x and y are mirrors when both are None, or both exist with equal values and x.left mirrors y.right and x.right mirrors `y.lef...