← All questions
EasyCoding
Maximum Depth of Binary Tree
Asked at
Blinkit
Infosys
Meta
Spotify
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+
- 01Define the depth of an empty subtree as zero.
- 02Recursively compute left and right subtree depths.
- 03Return one plus the larger child depth.
- 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
Hiring now
Spotify has 77 open roles right now
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
Senior Software Engineer
Remote
Senior Director, Global Advertising Product Marketing
New York, NY
Head of Measurement & Advertising Effectiveness
New York, NY
Next question