Maximum Depth of Binary Tree

Asked atBlinkitInfosysMetaSpotify
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Define the depth of an empty subtree as zero.
  2. 02Recursively compute left and right subtree depths.
  3. 03Return one plus the larger child depth.
  4. 04State whether the definition counts nodes or edges and handle an empty tree.

Reference answer

Then expect these follow-ups

  • How would you compute minimum depth?

    Tests: tree edge cases

  • When would BFS use less memory than DFS here?

    Tests: trade-offs

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question