Minimum Size Subarray Sum

You are given an array of positive integers nums and a positive integer target.

Return the length of the shortest contiguous subarray whose sum is greater than or equal to target. If no subarray reaches the target, return 0.

Constraints

  • 1 <= target <= 10^9
  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^4

Examples

Example 1

Input: target = 9, nums = [1,4,2,7,1,3]
Output: 2

[2, 7] sums to exactly 9. No single value reaches 9, so the answer is 2.

Example 2

Input: target = 5, nums = [1,1,1]
Output: 0

Even the whole array only sums to 3, so no subarray works: return 0.

Example 3

Input: target = 4, nums = [4,1]
Output: 1

The single value 4 already reaches the target.

JavaScript you'll use: Arrays: create, read, update Numbers, Math and integer tricks

/**
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */
function minSubArrayLen(target, nums) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.