Minimum Size Subarray Sum

Given an array of integers and a target, return the length of the shortest contiguous subarray whose sum is greater than or equal to the target.

Statement

Given an array of positive integers, nums, along with a positive integer, target. Find the length of the shortest contiguous subarray whose sum is greater than or equal to the target. If there is no such subarray, return 0 instead.

Example

Sample input

target = 7
nums = [2,3,1,2,4,3]

Expected output

2

Try it yourself

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.