33 / 75
E

Maximum Depth of Binary Tree

#33
treedfsbfs+1

Return max depth using DFS: 1 + max of left and right subtree depths.

Example:

Input:root=[3,9,20,null,null,15,7]
Output:3 (path: 3->20->15)

Common Mistakes:

  • Confusing depth with height (though they're same for trees)
  • Forgetting base case for null nodes
  • Counting edges instead of nodes (depth includes root)

Notes:

One of the simplest tree problems. Time O(n), Space O(h) for recursion stack. Can also solve with BFS level-order traversal.

33/75
Maximum Depth of Binary Tree