One pass beats many shifts.
transcript
A hundred thousand order ids. Forty thousand are cancelled. Delete each one by shifting. How long does it take?
Delete the zero at place one. Every entry after it moves left. That is five moves for one zero. Each deletion pays for the tail.
Forty thousand deletions. Each moves about half the list. The total is over two billion moves. At two nanoseconds, that is four seconds. Each deletion pays for the whole tail again. The cost grows with the square of the length.
Now use one pass instead. It reads each entry once. It writes only the kept entries. That is about a third of a millisecond.
Shifting makes billions of moves. The pass makes about one hundred sixty thousand steps. It is about twelve thousand times fewer. Both methods clean the same list. Only the method changed. Choose the method that touches each entry once.
Touch each entry once. Full breakdown in the lecture.