```
public int maxSubArrayLen(int[] nums, int k) {
int n = nums.length;
int max = 0;
int[] sums = new int[n];// sums[i] stores the sum of subarray starting at i
for (int i = 0; i < n; i++){
for (int j = 0; j <= i; j++){
sums[j] += nums[i];
if (sums[j] == k){
max = Math.max(max, i - j + 1);
}
}
}
return max;
}
```