Source: https://leetcode.com/problems/minimum-size-subarray-sum/

Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray [numsl, numsl+1, ..., numsr-1, numsr] of which the sum is greater than or equal to target. If there is no such subarray, return 0 instead.

/**
* @param {number} target
* @param {number[]} nums
* @return {number}
*/
// Brute force approach
// O(N^2) time, O(1) space
var minSubArrayLen = function(target, nums) {
let minLength = Infinity;
for (let i = 0; i < nums.length; i++) {
let sum = 0;
for (let j = i; j < nums.length; j++) {
sum += nums[j];
if (sum >= target) {
minLength = Math.min(minLength, j - i + 1);
break;
}
}
}
return minLength !== Infinity ? minLength : 0;
};