Deduplicate a sorted array

Removing duplicates from a sorted array can be done in:

Show hints (2)+
  1. The array is already sorted — duplicates are adjacent.
  2. Compare each element with the previous one.

Answer

Reveal answer →

O(n) time, O(1) extra space

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: Optiver, IMC

Related questions