AAlgoLab
ALG-M006MediumSliding Window

Shortest Sufficient Segment

Given positive integers and a positive target, return the minimum length of a contiguous subarray whose sum is at least target. Return 0 if none exists.

Contract

input numbers: integer[]
input target: integer
return integer

Constraints

  • • Every array value > 0
  • • target > 0
  • • 0 <= length <= 100000

Examples

Example 1
numbers = [2, 3, 1, 2, 4, 3]
target = 7
→ 2
Example 2
numbers = [1, 1, 1]
target = 10
→ 0

5 judge tests (2 shown above). Target complexity: O(n).