easyTreeTrees

Maximum Depth of Binary Tree

easyTime: O(n)Space: O(h)

Signals to notice

find deepest pathtree heightrecursive structure

Brute force first

BFS level by level, count levels — but uses more memory. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.

The key insight

Recursive DFS: depth = 1 + max(left depth, right depth). Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.

What must stay true

The depth of a node is 1 plus the maximum depth of its children. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.

Easy way to go wrong

Confusing depth vs height — depth of a null node is 0, not -1. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.

Trees Pattern