Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Count the triples of indices i < j < k in [2, 5, 1, 7, 3, 4, 6] with a[i] + a[j] + a[k] ≤ 12.

  1. A. 15
  2. B. 120
  3. C. 20
  4. D. 35

Correct answer: C. 20

Brute force over the 35 triples finds 20 with sum ≤ 12 (sort plus two pointers does it in O(n²)). Using < 12 gives 15, counting ordered triples multiplies by 3! (120), and 35 counts every triple.

More Coding Interview Problems questions

Exams that ask this topic