Remove Duplicates from Sorted Array
The writer only copies a value that differs from the last one it kept.
Decision · step 2 of 10Two Pointers: Remove duplicates
1 equals the last kept value, so it is skipped. The writer stays put.
What you will see
Duplicates are skipped by the reader; the compacted prefix grows.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Pointers announce their name and index; each step announces which pointer moved and why.
Reduced motion: Pointers appear at their new index with a brief emphasis instead of gliding.
Before this
Taught by the same lesson
Two Pointers covers these too, in the same run.