Writes in an in-place dedup
The standard in-place two-pointer dedup runs on the sorted array : a write pointer starts on the first (kept) element, and for each later element the read pointer visits, the algorithm advances and executes arr[w] = arr[r] only when that element is a new value. Counting only those arr[w] = arr[r] write operations, how many writes occur?
Show hints (2)+
- A write fires only on a new value; runs of duplicates and the in-place first element write nothing.
- Writes (distinct values) .
Answer
Reveal answer →Final answer
4
Create a free account to see the full worked solution and track your progress.
Interview format: Numerical Reasoning Tests, Trading Aptitude Tests