imashutosh51

Minimum Size Subarray Sum

Mar 23rd, 2026
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. class Solution:
  2.     def minSubArrayLen(self, target: int, nums: List[int]) -> int:
  3.         cur=0
  4.         ans=pow(10,8)
  5.         k=0
  6.         for i in range(len(nums)):
  7.             cur+=nums[i]
  8.             while cur>=target:
  9.                 ans=min(i-k+1,ans) #doing comparison everytime will reduce the size and won't impact the answer also.
  10.                 cur-=nums[k]
  11.                 k+=1
  12.         return ans if ans!=pow(10,8) else 0
  13.        
Advertisement
Add Comment
Please, Sign In to add comment