Invert Binary Tree
Swap children at every node.
Approach
Recursively (or with a stack/queue) visit each node and swap its left and right children. DFS or BFS both work since you touch every node exactly once. The recursion bottoms out at nulls.
Time complexity
O(n)
Space complexity
O(h) recursion
Common mistake
Swapping values instead of the child pointers, or forgetting to recurse into both subtrees.
See it run, step by step
Generate an interactive lesson for Invert Binary Tree — trace every variable and watch the algorithm execute until it clicks.
Start a lesson on Invert Binary Tree