# your code goes here
class Solution(object):
    def maxSubarrayLessOrEqualToK(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        i = 0          # Left pointer of the window
        s = 0          # Running sum of the current window
        max_len = 0    # Tracks the maximum length found
        
        for j in range(len(nums)):
            s += nums[j]
            
            while s > k and i <= j:
                s -= nums[i]
                i += 1
            
            if s <= k:
                max_len = max(max_len, j - i + 1)
        
        return max_len
