Start from the answer
transcript
A map stores the height of every cell. Rain runs to a neighbour that is not higher. Which cells drain to the river? Do not follow every drop.
The first plan follows the water from every cell. Every walk revisits the same cells. It does not scale.
Rain flows from a cell to a neighbour that is not higher. The two rivers sit on the edges of the map. So the edges are the natural starts.
On a thirty by thirty map, that is 810,000 visits. Two walks from the edges make eighteen hundred.
Reverse the walk. Start at the river's edge. Step to any neighbour that is equal or higher. Mark each cell when it joins.
Do the same for the second river. Keep the cells that both walks reached.
Write the neighbour rule first. Start where the answer lives. Mark a cell when it joins. Full breakdown in the lecture.