Data Structures & AlgorithmsModerateGATE CS · Product placement

Assertion (A): Removing duplicates from a sorted array can be done in place in O(n) time with two pointers. Reason (R): In a sorted array, equal elements are adjacent, so a value is new exactly when it differs from the last kept value.

  1. A. Both A and R are true, and R is the correct explanation of A
  2. B. A is false, but R is true
  3. C. Both A and R are true, but R is not the correct explanation of A
  4. D. A is true, but R is false

Correct answer: A. Both A and R are true, and R is the correct explanation of A

Because duplicates are contiguous, one read pointer and one write pointer suffice; R is the reason this works without a hash set.

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

Exams that ask this topic