Tree Modification
DFS First
226. Invert Binary Tree
Invert a binary tree by swapping the left and right subtrees of every node, so the result is the mirror image of the input.
Exchange the Leaf Nodes
Pairwise swap all leaf nodes of a binary tree. If there are odd number of leaf nodes, the last leaf node remains unchanged.
617. Merge Two Binary Trees
Overlay the two trees: where both have a node, the merged node holds the sum of their values; where only one has a node, that subtree is carried over unchanged. A parallel DFS walks both trees in lockstep, building the merged tree node by node.
2415. Reverse Odd Levels of Binary Tree
The tree is perfect, so reversing a level means swapping values between nodes that are mirror images of each other across the tree's vertical axis. Walk mirror pairs instead of whole levels and each swap is a single exchange.
814. Binary Tree Pruning
Remove every subtree that contains no 1. Post-order is what makes this work: a child is pruned before its parent reports up, so by the time a parent looks at a child it is already the collapsed version of itself.
rec returns a pair (zero_flag, total) - whether the subtree is all zeros, and how many nodes it still has after pruning. A child is cut when zero == total, which holds in exactly two cases: the child is absent (0 == 0), or it survived as a single all-zero node (1 == 1). Because both children are detached before the parent returns left_total + right_total + 1, any all-zero subtree keeps shrinking to one node on the way up, so it is always caught. The root gets the same test via rec(root) == (1, 1).
Create a New Tree
654. Maximum Binary Tree
Build the tree recursively: the largest value in the current range becomes the root, the elements to its left form the left subtree, and the elements to its right form the right subtree. Repeating this on each half constructs the maximum binary tree.
BFS First
116. Populating Next Right Pointers in Each Node
Given a perfect binary tree, populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
FOLLOW UP: You may only use constant extra space.

117. Populating Next Right Pointers in Each Node II
TODO: Undertsnad the optimal approach with constact auxillary space
Given a binary tree, populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
FOLLOW UP: You may only use constant extra space.
623. Add One Row to Tree
Insert a whole row of val nodes at depth. Every node that was at depth keeps its subtree - it just gets re-parented, a left child staying a left child and a right child staying a right child. So the real work happens at level depth - 1, and depth == 1 is its own case because there is no parent level to work from.