Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many index triples i < j < k in [-2, -1, 0, 1, 2, 3] have a sum of exactly 0?

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

Correct answer: C. 3

After sorting, fix the first index and run two pointers on the rest; each zero-sum triple is found exactly once. Duplicate values would need careful skipping, but none are present here.

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

Exams that ask this topic