Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many index triples i < j < k in [2, 3, 4, 5, 7, 10] can be the three sides of a non-degenerate triangle (sum of the two smaller sides strictly greater than the largest)?

  1. A. 8
  2. B. 6
  3. C. 7
  4. D. 10

Correct answer: C. 7

After sorting, fix the largest side k and use two pointers over the smaller sides: if a[i] + a[j] > a[k], all indices between i and j-1 also work. The strict inequality matters for equal sums.

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

Exams that ask this topic