easyTreeTrees

Symmetric Tree

easyTime: O(n)Space: O(h)

Signals to notice

mirror image checkcompare left with rightstructural equality

Brute force first

Generate both subtrees as arrays and compare — but wasteful. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.

The key insight

Recursive comparison: left.left matches right.right, and left.right matches right.left. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

Two subtrees are mirrors if outer children match and inner children match. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Only checking values without checking structure — both values AND structure must mirror. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Trees Pattern