80. Minimum Size Subarray Sum

MediumArrayArray

Given positive integer target and positive integer array nums, return the minimal length of a subarray with sum >= target. If impossible, return 0.

Input: Positive integer target and positive integer array nums.

Output: Minimum subarray length or 0.

Examples

Example 1
Input: 7,[2,3,1,2,4,3]
Output: 2
Explanation: [4,3] has sum 7, length 2.
Example 2
Input: 4,[1,4,4]
Output: 1
Explanation: [4] has sum 4.
Example 3
Input: 11,[1,1,1,1,1,1,1,1]
Output: 0
Explanation: Total sum 8 < 11.

Constraints

Asked by

HCLTechBloombergMicrosoftAmazonMetaGoogle
Solve this problem in the editor →