This problem follows the Recursive DFS pattern, commonly found in the Trees category. Recognizing this pattern is key to solving it efficiently in an interview setting.
Return 1 + max(depth(left), depth(right)). Base case: null returns 0.
The height of a tree is defined recursively — a null tree has height 0, otherwise it's 1 + the taller subtree.
def maxDepth(root):
if not root: return 0
return 1 + max(maxDepth(root.left), maxDepth(root.right))Practice Maximum Depth of Binary Tree and similar Trees problems with flashcards. Build pattern recognition through active recall.
Practice this problem