easyTreesPure DSA~15 min
UI Layout Mirror Check
A design-system linter verifies that a component's layout tree is a perfect left-right mirror of itself — the visual hallmark of a balanced, symmetric card. Given the layout tree, decide whether it is mirror-symmetric.
Problem
Given the root of a binary tree, return true if it is a mirror image of itself around its centre.
Input
The root of a tree with n nodes (0 ≤ n ≤ 10^4), shown in level order with null for missing children.
Output
A boolean — true if the tree is symmetric.
Constraints
- 0 ≤ n ≤ 10,000
- Node values fit in a 32-bit int
- An empty tree is symmetric
Examples
Example 1
Input
root = [1, 2, 2, 3, 4, 4, 3]
Output
true
The left subtree is the mirror of the right subtree at every level.
Example 2
Input
root = [1, 2, 2, null, 3, null, 3]
Output
false
The dangling 3s sit on the same side, breaking the mirror.