binary tree
4
2
5
1
3
call stack ↓
(returned)
Recursive DFS (post-order height + global max)
▸1best = 02height(node):3 if node is null: return -1 // base case4 L = height(node.left)5 R = height(node.right)6 best = max(best, (L+1) + (R+1)) // path through node7 return 1 + max(L, R) // height for parent8// answer = best
state
- goallongest path in edges
- global best0