Given a binary tree, find its maximum depth — the number of nodes along the longest path from root to the farthest leaf.
This is the simplest recursive tree problem — the hello world of tree recursion:
This pattern — combine results from left and right subtrees — is the foundation of almost every tree problem.
max_depth(root)
3
max_depth(None)
0
max_depth(TreeNode(1))
1