fork download
  1. # your code goes here
  2. class Solution(object):
  3. def maxSubarrayLessOrEqualToK(self, nums, k):
  4. """
  5. :type nums: List[int]
  6. :type k: int
  7. :rtype: int
  8. """
  9. i = 0 # Left pointer of the window
  10. s = 0 # Running sum of the current window
  11. max_len = 0 # Tracks the maximum length found
  12.  
  13. for j in range(len(nums)):
  14. s += nums[j]
  15.  
  16. while s > k and i <= j:
  17. s -= nums[i]
  18. i += 1
  19.  
  20. if s <= k:
  21. max_len = max(max_len, j - i + 1)
  22.  
  23. return max_len
  24.  
Success #stdin #stdout 0.07s 13992KB
stdin
Standard input is empty
stdout
Standard output is empty