intro practice · coding problem
Maximum Depth of Binary Tree
LeetCode #104 — Maximum Depth of Binary Tree. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/maximum-depth-of-binary-tree/
The mechanism
A tree is recursion made concrete: almost every tree problem is "solve it for the children, then combine". DFS (pre/in/post-order) is a recursion or an explicit stack; BFS is a queue, level by level. Pick the traversal that matches what you need to combine.
Expected evidence
Pass all LeetCode test cases for this problem.
Try this drill in the practice workspace →
Hints when you need them
- Pattern hint: trees.
- Start with brute force, then optimize time/space.
- Write down invariants before coding.
Watch for these mistakes
- Forgetting the null/empty base case
- Using DFS when the problem is about levels or shortest depth (use BFS)
- Returning the wrong thing from recursion — separate "answer" from "info passed up"