@imba_keridy incase of sum-k = 0, we'd better have put(0,-1) in map so that current index - (-1) is the correct size of the subarray that sums up to k.

Here's my cleaner version:

public int maxSubArrayLen(int[] nums, int k) { int index = -1,sum = 0,max = 0; HashMap<Integer,Integer> sum_size = new HashMap<Integer,Integer>(); sum_size.put(0,index); while(++index<nums.length){ sum+=nums[index]; Integer presumIndex = sum_size.get(sum-k); if(presumIndex!=null&&max<index-presumIndex) max = index-presumIndex; sum_size.put(sum,sum_size.getOrDefault(sum, index)); } return max; }