Data Structures & AlgorithmsHard

How many index triples i < j < k in the sorted array [-2, 0, 1, 3, 5, 6] have A[i] + A[j] + A[k] strictly less than 4?

  1. A. 4
  2. B. 7
  3. C. 13
  4. D. 6

Correct answer: A. 4

Fix the smallest index i, then a two-pointer sweep over j and k counts every valid triple in one pass once the array is sorted. Replacing < with ≤ changes boundary cases, the complementary count is the wrong side, and dropping a term counts pairs instead of triples.

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

Exams that ask this topic