Restart when the balance fails
transcript
A trail runs in a circle. Six huts refill your bottle. Walking uses water. It sounds like a hard search. It is not. One number is enough. Where should you start?
Each hut has a net gain. It is the refill, minus the walk. Hut one loses four. Positive gains refill the bottle. Negative gains drain it. The bottle starts empty. It must never go below zero.
Add each gain to the bottle. If it goes below zero, restart at the next hut. Empty the bottle. Keep the total. A failure rules out every start before it. So we never look back. The scan is one pass.
Hut zero: the bottle is one. Hut one: minus three. Below zero. Restart at hut two. The bottle stays up to hut five. Everything before hut two is forgotten. Nothing there could have worked.
The total is three. It is not negative. So hut two works. One pass. No sorting. Full breakdown in the lecture.