Data Structures & AlgorithmsHardCodeforces Div 2 C · ICPC regional

From the sorted side lengths [4, 6, 7, 9, 10, 13, 15], how many different triples (choosing distinct positions) can form a non-degenerate triangle, i.e. the sum of the two smaller sides is strictly greater than the largest?

  1. A. 26
  2. B. 24
  3. C. 23
  4. D. 28

Correct answer: B. 24

With sorted sides, fix the largest side c, then two pointers over the smaller ones count every pair whose sum exceeds c in linear time. Using >= counts degenerate triples where the two shorter sides exactly add up to the longest.

More Coding Interview Problems questions

Exams that ask this topic