DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Minimum Size Subarray Sum

var minSubArrayLen = function(target, nums) {
    let counter = Infinity;
    let start = 0;
    let sum = 0;


  for (let i = 0; i < nums.length; i++) {
      sum= sum + nums[i];

      while(sum>=target){
           counter = Math.min(counter, i-start +1)
            sum= sum - nums[start];
          start++;

      }     
  }

if(counter === Infinity){
    return 0;
}
    return counter;

};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)