Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

How many index pairs i < j in the sorted array [1, 2, 4, 6, 7, 9] satisfy a[i] + a[j] <= 10?

  1. A. 10
  2. B. 11
  3. C. 13
  4. D. 9

Correct answer: D. 9

With a sorted array, a two-pointer scan counts all valid right partners for each left index in one pass. Pairs with sums exactly 10 count as valid.

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

Exams that ask this topic