Data Structures & AlgorithmsHard

Count the pairs of positions i < j in 2 5 3 2 4 5 6 3 with EQUAL values such that the value does not occur strictly between them (i and j are consecutive occurrences of that value).

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

Correct answer: C. 3

Consecutive occurrences of a value are the pairs with no equal value in between, and there are (count − 1) such pairs per value. Counting all equal pairs includes non-consecutive ones, and the distance filter removes valid consecutive pairs.

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

Exams that ask this topic