Save the diagonal
transcript
A move can go diagonally. A cell now reads three cells. One row of memory seems enough. But the diagonal gets lost.
In one row, the diagonal is the old left cell. But the left cell was overwritten a moment ago. So the old value is gone, and the cell cannot read it.
Take the grid one, minus nine; minus nine, one. The start holds one. The other cells hold minus eight. The last cell reads three cells. The diagonal gives two.
Now take zero, minus one; minus two, one. Without the variable, the code reads the left cell twice. It returns zero. Save the old value before the overwrite. Then the answer is one.
The largest square of free desks reads the diagonal. It uses the same saved variable. Learn the trick once. Use it in every grid problem that reads the diagonal.
Save the old value before you overwrite it. Then the diagonal is safe for the next column. Do this in every row. Full breakdown in the lecture.