#1 most askedVery commonEasyTree DFS
Maximum Depth of Binary Tree
New to Tree DFS? Learn it from scratch firstTrees & Binary Search Trees β
π’ Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.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.
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.