binary tree
1
4
1
5
5
5
call stack ↓
(returned)
Recursive DFS (post-order arrows + global max)
▸1best = 02arrow(node):3 lRaw = arrow(node.left); rRaw = arrow(node.right)4 lArm = (left matches) ? lRaw + 1 : 05 rArm = (right matches) ? rRaw + 1 : 06 best = max(best, lArm + rArm) // path bending here7 return max(lArm, rArm) // arm for parent8// answer = best
state
- goallongest equal-value path
- global best0