visual walkthrough
Remove Duplicates from Sorted Array
Introduces the reader/writer pointer pair.
The idea
Because the array is sorted, duplicates sit next to each other. A `read` pointer scans every value while a `write` pointer marks the end of the unique prefix.
When the value at `read` differs from the last kept value, copy it forward. Everything left of `write` is the answer.
Complexity
| approach | time | space |
|---|---|---|
| Copy to a new list | O(n) | O(n) |
| Read / write pointers | O(n) | O(1) |