FreeCareerPath
Build the PrimitiveEasy

Maximum Depth of Binary Tree

Write `max_depth(root)` returning the number of nodes on the longest path from the root down to a leaf. An empty tree has depth 0. The recursive answer is one line. The reason this is asked at all is the follow-up: give the iterative BFS version too, and say which uses less memory on a wide tree versus a deep one.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Maximum Depth of Binary Tree" are saved to your account — logging in takes a few seconds.

Maximum Depth of Binary Tree — FreeCareerPath