Phase 1: Look at the tree and its mirror, then swap the root's children.

The most famous interview question in history. Three lines of code. It allegedly cost the creator of Homebrew a Google offer. Look at this tree, then look at its mirror image — your job is to make the left look like the right.

Given a binary tree, return its mirror image: at every node, the left child becomes the right child and vice versa, all the way down. One rule — you can only swap children at a node, never move individual values around.

FIG. 1 — THE TREE AND ITS MIRROR
Input
Goal
— A goal you can see, not derive —

Trace the path from root to leaf 1. In the input it goes left-left (4 2 1). In the goal it goes right-right (4 2 1). Every left became a right. Now check leaf 9: right-right in the input, left-left in the goal. The mirror is exact — and it runs all the way down.

You can't just rearrange the values printed at each position — the tree is a mesh of references between nodes, and one wrong move (swapping at the wrong moment, or swapping the wrong layer) orphans an entire subtree. The question is: what's the smallest move at each node that gets the whole tree there?

FIG. 2 — TRY IT: SWAP THE ROOT'S CHILDREN

Start where it's easiest — at the very top. Tap the root to swap its two children, then look at the result. Did the tree end up fully mirrored?