Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Sorted side lengths [3, 5, 7, 9, 11, 13]. How many triples of distinct sides form a non-degenerate triangle with perimeter at most 20?

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

Correct answer: C. 2

For a sorted triple, the triangle inequality reduces to the two smaller sides summing above the largest. A two-pointer scan with the perimeter bound gives the count; using >= admits degenerate triangles.

More Coding Interview Problems questions

Exams that ask this topic