Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

How many triples (a, b, c) with a < b < c taken from the set [1, 2, 3, 4, 5, 6, 8, 10, 12] satisfy a + b = c?

  1. A. 12
  2. B. 14
  3. C. 11
  4. D. 6

Correct answer: A. 12

Sort the set and, for each pair (a, b), check whether a + b is present using a hash set. Requiring only a + b = c without the ordering a < b < c double-counts the same triple.

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

Exams that ask this topic