Example
Input
target = 7, nums = [2,3,1,2,4,3]
Output
2
The subarray [4,3] has the minimal length 2 with sum >= 7.
Full lesson preview
Given an array of positive integers and a target sum, find the minimal length of a contiguous subarray whose sum is at least the target.
Problem statement
Task
Examples
Input
target = 7, nums = [2,3,1,2,4,3]
Output
2
The subarray [4,3] has the minimal length 2 with sum >= 7.
Input format
Output format
Constraints
Samples
Input
target = 4, nums = [1,4,4]
Output
1
Single element 4 meets the target; minimal length is 1.