Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

What is the length of the shortest contiguous subarray of [5, 1, 4, 3, 2, 6, 7] whose sum is at least 15?

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

Correct answer: C. 3

A two-pointer scan over positive numbers finds the shortest qualifying window, and checking every window confirms it. Taking the first qualifying window instead gives a longer one.

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

Exams that ask this topic