Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] = 10?

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

Correct answer: C. 3

Fix the smallest index and look for pairs in the rest that sum to the remaining value; the triples are ordered by index, so each set counts once.

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

Exams that ask this topic