Data Structures & AlgorithmsHard

Remove duplicate values from the unsorted list 4 2 4 1 2 5 1 so that only ONE copy of each value remains, keeping the copy that appears LAST in the original order. Give the remaining sequence.

  1. A. 4 2 5 1
  2. B. 4 2 1 5
  3. C. 1 2 4 5
  4. D. 5

Correct answer: A. 4 2 5 1

Scanning from the right and keeping a value only at its final occurrence retains the last copy in original relative order. Keeping the first occurrence, sorting, or deleting every repeated value gives the other sequences.

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

Exams that ask this topic