Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j} once?

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

Correct answer: C. 4

For each unordered pair {i, j}, look up a[i] + a[j] in a hash map of values and check the index differs from i and j. Equal values need separate index checks.

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

Exams that ask this topic