Delete, move on, miss a no-read.
transcript
This loop deletes every no-read. Or does it? One no-read always survives it.
Four scans. Two no-reads sit side by side. The gate must upload only real scans. The answer should be 52 and 18.
The loop is on index 1. It finds minus 1. It deletes it. The next scan slides into index 1. Then the loop moves on to index 2. The second minus 1 sat in index 1. Nobody checked it. Every deletion hides the next scan this way.
The bug returns 52, minus 1, 18. The right answer is 52, 18.
One fix: stay on the same index after a deletion. But each deletion still slides the rest. That is slow. Better: read every scan, and write only the keepers.
With read and write, nothing slides. Read visits every scan exactly once. So no scan can be skipped. And each kept scan is copied only once. Correct and fast, in the same buffer.
Full breakdown in the lecture.