DSA · Trees · #176
Symmetric Tree
Module 44 · difficulty 2/5·⏱ 30:00starts on first keystroke
Given the `root` of a binary tree, return `true` if the tree is a mirror of itself (symmetric around its center), otherwise return `false`. A tree is symmetric when the left subtree is a mirror reflection of the right subtree. Implement the function `isSymmetric(root)`. Each node is `{ val, left, right }`; an empty tree is represented by `null`.
Examples
root = [1,2,2,3,4,4,3]→true— The two subtrees of the root mirror each other exactly.root = [1,2,2,null,3,null,3]→false— The 3s are positioned on the same side, breaking mirror symmetry.root = []→true— An empty tree is trivially symmetric.
Constraints
- · The number of nodes is in the range [0, 1000].
- · -100 <= Node.val <= 100
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.