Minimum Size Subarray Sum
You get an array of positive numbers and a target. Find the length of the shortest run of numbers in a row whose sum is at least the target, or 0 if there is none. Our example: [3, 1, 4, 2, 6, 5, 1] and target = 11 — the answer is 2: 6 + 5 = 11.
- input
target: a positive integer;nums: an array of positive integers.- returns
- The smallest length of a contiguous subarray of
numswhose sum is at leasttarget, or0if there is none. - constraints
- 1 ≤ target ≤ 10⁹
- 1 ≤ nums.length ≤ 10000
- 1 ≤ nums[i] ≤ 10⁴
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {number} target
* @param {number[]} nums
* @return {number}
*/
function minSubArrayLen(target, nums) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more sliding window problems
- 643Maximum Average Subarray IEasysolve
- 28Find the Index of the First Occurrence in a StringEasysolve
- 3Longest Substring Without Repeating CharactersMediumsolve
- 424Longest Repeating Character ReplacementMediumsolve
- 567Permutation in StringMediumsolve
- 76Minimum Window SubstringHardsolve
- 30Substring with Concatenation of All WordsHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.