# Minimum Size Subarray Sum

• specific exlpain,thanks

• This is picky, but idiomatic C++ uses static_cast<int> instead of C style cast (int) as seen in approach 3.

• @sean46 Thanks for the suggestion. Made the change :)

• input
11
[1,2,3,4,5]
expected 3

• whaat

• srry more or equal..

• ``````int sum = 0;
int n = nums.length;
int res = Integer.MAX_VALUE;
int l = 0;
for(int r = 0; r < n; r++){
sum += nums[r];
while (sum >= s){
res = Math.min(res, r-l+1);
sum -= nums[l++];
}
}
return res == Integer.MAX_VALUE ? 0 : res;
``````

• Good! Thank you!

• input
11
[1,2,3,4,5]
expected 3
How this is possible. I guess for this out put it should return 0 because
2+4+5 =11, 1+2+3+5 =11

``````def minSubArrayLen(self, target_sum, a):
"""
:type s: int
:type nums: List[int]
:rtype: int
"""
found = False
if a == []: return 0
sum = p1 = 0
min_sub_a = len(a)-1
for i in range(len(a)):
sum = sum + a[i]
while sum >= target_sum:
sum -= a[p1]
p1 += 1
if sum == target_sum:
found = True
min_sub_a = min(min_sub_a, len(a[p1:i+1]))
if found == True:
return min_sub_a
else:
return 0``````

• @dharpatel Problem statement is to look for sums greater than target value, not equal. [3,4,5] is 12 which is greater than 11 and thus the minimum length is 3.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.