Medium · Strings
Shortest subarray with sum at least target
Given an array of positive integers nums and a positive integer target, return the length of the shortest contiguous subarray whose sum is at least target, or 0 if no such subarray exists.
Examples
Example 1
[2,3,1,2,4,3] → 7Output: 2
Example 2
[1,1,1,1] → 6Output: 0 (no subarray)
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.