Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

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

  1. A. 12
  2. B. 9
  3. C. 20
  4. D. 6

Correct answer: D. 6

The value triples are 1+2=3, 1+3=4, 1+4=5, 2+3=5, 1+5=6, 2+4=6, so 6. Counting (i, j) and (j, i) separately gives 12, allowing i = j adds 1+1, 2+2, 3+3 for 9, and 20 is the number of all triples.

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

Exams that ask this topic