Every other door fails
transcript
A courier visits doors in a row. No two neighbours may both be taken. Take every other door. Easy? It passes the usual example. It looks like a safe way to avoid neighbours.
Here are the tips at four doors. Every other door takes the first and third: six. But the first and last door are not neighbours. They are three doors apart, so both are allowed.
Every other door gives six. The best plan gives ten. It skips two doors in a row. The plan skips the two middle doors.
At each door, skip it and keep the total. Or take it, and add the total from two doors back. Keep the larger of the two. That is the whole table.
Only the last two totals matter. So two variables replace the table. The answer is the larger one at the end. It uses almost no memory.
Test five, one, one, five. The answer must be ten. Full breakdown in the lecture.