โ† Trees, Graphs & DP
#1 most askedVery commonEasyTree DFS

Maximum Depth of Binary Tree

New to Tree DFS? Learn it from scratch first
Trees & Binary Search Trees โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

Return the number of nodes on the longest path from the root down to a leaf. (TreeNode, build_tree and tree_values are built in. Trees are written level by level, with None for missing children.)

build_tree([3, 9, 20, None, None, 15, 7]) โ†’ 3

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def max_depth(root):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.