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
Want the full step-by-step worked solution? It's part of Premium - along with a worked solution for every question in the bank.
Asked at: Timed Mental-Math & Sequences, Game-Based Aptitude