Data Structures & AlgorithmsHardTCS NQT · Accenture

For the array [1, 2, 2, 3], how many distinct sums a[i] + a[j] are formed by pairs with i not equal to j (ordered pairs)?

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

Correct answer: B. 3

The distinct sums are 3 (from 1 + 2), 4 (from 1 + 3 and 2 + 2) and 5 (from 2 + 3). Counting every ordered pair instead gives a larger number.

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

Exams that ask this topic