Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

In [3, 8, 1, 6, 9, 4], find the pair of distinct indices (i < j) with a[i] + a[j] = 10, minimising i + j. What is the minimum value of i + j?

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

Correct answer: B. 6

With a hash map of earlier values, pairs summing to 10 are (indices 2, 4: 1 + 9) and (3, 5: 6 + 4), so the minimum index sum is 6. The other pair gives 8, as does using 1-based indices; 2 reports i alone and 10 is the target.

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

Exams that ask this topic