EvalFrame Technical Mock Interviews & Coding Practice

Maximum Depth of Binary Tree

Easy · Binary Tree · Algorithm problem · all problems

Given the root of a binary tree represented as an array in level-order, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. **Examples:** ```typescript maxDepth([3, 9, 20, null, null, 15, 7]) // 3 maxDepth([1, null, 2]) // 2 ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n)
  • Space complexity: O(h)

Visits every node once via recursive DFS in O(n) time.

Follow-Up Questions Interviewers Ask About Maximum Depth of Binary Tree

  • What is the iterative BFS approach for maximum depth?
    Use a queue to process level by level, incrementing depth by 1 for each level of the tree processed.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.