```
def max_sub_array_len(nums, k)
sums = {}
cur_sum = 0
max_len = 0
sums[0] = -1
(0...nums.length).each do |i|
cur_sum += nums[i]
sums[cur_sum] ||= i
j = sums[cur_sum - k]
max_len = [i - j, max_len].max if j
end
return max_len
end
```