public int maxSubArrayLen(int[] nums, int k) {
if(nums==null  nums.length==0) return 0;
final int N = nums.length;
// do sum
for(int i=1; i<N; i++){
nums[i] += nums[i1];
}
int max = 0;
Map<Integer, Integer> map = new HashMap<>(); // sum : index
// in case sum[i]==0
map.put(0, 1);
for(int i=0; i<N; i++){
if(!map.containsKey(nums[i])){
map.put(nums[i], i);
}
Integer j = map.get(nums[i]k);
if(j != null){
max = Math.max(max, ij);
}
}
return max;
}
Java O(n) solution, using map


@MadDetective Wouldn't that be concidered a O(2n) solution since you go through the length of nums (n) twice?

@niklaos
O(2n) = O(n)
O(n) means that the runtime increases linearly with the size of input.https://stackoverflow.com/questions/19371489/whyisonequaltoo2n
