Grow an array from the back.
transcript
Double every zero in place. The array keeps its length. Start from the front? Watch what breaks.
The list is one, zero, two, three. The zero must appear twice. Write the second zero at place two. That overwrites the two.
The three is overwritten next. The forward version returns one, zero, zero, zero. The right answer is one, zero, zero, two. Write ran ahead of read.
Count the zeros first. There is one. Read from the back, write from the back. The three goes beyond the end, so it is dropped. The two goes to place three. The zeros fill places one and two.
Moving from the back, write stays ahead. But it writes on places already read. Nothing unread is overwritten. Grow from the back. A forward write ran ahead of read. A backward write starts where nothing is unread. The rule works for any longer edit.
Longer edits write from the back. Full breakdown in the lecture.