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] → 7

Output: 2

Example 2

[1,1,1,1] → 6

Output: 0 (no subarray)

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems