| Random Link ¯\_(ツ)_/¯ | ||
| May 28, 2026 | » | Remove Duplicates from Sorted Array
1 min; updated May 28, 2026
Given a sorted integer array, remove some duplicates in-place such that each unique element appears at most twice. Maintain the relative order of the elements. If there are \(k\) elements after removing the duplicates, the first \(k\) elements of the array should hold the final result. This a two-pointer problem, where we have a tortoise and a hare. Establishing an
invariant that must be maintained throughout the array is useful to avoid
tripping up on index arithmetic. In this case, let |