Data Structures & AlgorithmsModerateTCS NQT · Infosys

An array is [1, 2, 1, 2, 1, 2] (indices 0 to 5). How many pairs of even-indexed positions i < j hold equal values?

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

Correct answer: B. 3

The even indices 0, 2, 4 all hold 1, which gives 3 equal pairs. The odd-indexed 2s are excluded by the restriction.

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

Exams that ask this topic