Two pointers clean a list.
transcript
Seven ids. Three are cancelled. Remove them. Keep the order. Use no second array. Two pointers do it.
The ids are seven, zero, four, zero, zero, nine, three. Read visits every entry. Write marks the next free place. Both start at place zero.
Seven is kept. Write moves to one. The zero is skipped. Four is kept. Copy it to place one. Write moves only on a keep.
Nine goes to place two. Three goes to place three. Write is four at the end. The first four entries are the answer.
Write never passes read. So each copy lands on a place already read. No unread entry is lost. One pass. No second array. The same idea cleans a stream of data. Each entry is looked at once, then forgotten. It is a pattern worth knowing well. Memory use stays constant, whatever the length.
Read ahead. Write behind. Full breakdown in the lecture.