Data Structures & AlgorithmsVery hard

In 3 1 4 1 5 9 2 6 5 3, what is the largest possible index distance j − i between two positions i < j that hold EQUAL values?

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

Correct answer: A. 9

For each value record its first and last positions; the widest gap for a value is last minus first, and the answer is the maximum over all values. Using the nearest pair, the array length, or unequal pairs misreads the question.

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

Exams that ask this topic