Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

A sorted array is [1, 9, 9, 10, 13, 14, 18, 23, 23, 25]. Using the standard two-pointer in-place duplicate-removal technique (a slow pointer marks the last unique position, a fast pointer scans ahead), how many elements remain after duplicates are removed?

  1. A. 7
  2. B. 9
  3. C. 8
  4. D. 10

Correct answer: C. 8

The slow pointer only advances on a new distinct value, so the final count equals the number of distinct values, 8 (there were 2 duplicate occurrence(s)).

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic