Data Structures & AlgorithmsHardTCS NQT · Infosys

How many index pairs i < j in [1, 2, 3, 4, 5, 6, 7, 8] have equal parity and a[i] + a[j] <= 10?

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

Correct answer: D. 9

Group odds and evens separately; within each group count the pairs whose sum is at most 10, using sorting and two pointers.

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

Exams that ask this topic