Data Structures & AlgorithmsHardCAT · ICPC regional

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

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

Correct answer: C. 4

Negative values break the two-pointer shrink rule, so prefix sums with a monotone deque (or direct checking on this small array) are needed.

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

Exams that ask this topic