The top is not the answer
transcript
A show lets viewers press left or right. Find the longest left-right route. Each move must switch sides after the first one. Where does the best route start?
Each node returns two lengths to its parent. One route starts with a move left. The other starts with a move right. Both come from the children.
Five nodes in a line. The moves are right, right, left, right. Node two gives two, if it goes left first. Node one gives three, if it goes right first. That is the best route. The top gives only one. Its second move has no node.
Read only the top, and the answer is one. That is wrong. Keep the best over every node. The answer is three.
Compute the pair of each node, bottom up. Update a running best after each pair. Read the best at the end, not the top.
A route can start anywhere. Keep a running best. Full breakdown in the lecture.