@@ -0,0 +1,1425 @@
+package medium;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport utils.CommonUtils;%0A%0Apublic class MaximumSizeSubarraySumEqualsK %7B%0A    public int maxSubArrayLen_On_solution(int%5B%5D nums, int k) %7B%0A        Map%3CInteger, Integer%3E map = new HashMap();%0A        int sum = 0, max = 0;%0A        for(int i = 0; i %3C nums.length; i++)%7B%0A            sum += nums%5Bi%5D;%0A            if(sum == k) max = i+1;%0A            else if(map.containsKey(sum-k)) max = Math.max(max, i-map.get(sum-k));%0A            if(!map.containsKey(sum)) map.put(sum, i);%0A        %7D%0A        return max;%0A    %7D%0A%0A    %0A    public static int maxSubArrayLen_On2_solution(int%5B%5D nums, int k) %7B%0A        //NOTES: didn't finish this one%0A        int%5B%5D sums = new int%5Bnums.length%5D;%0A        int max = 0;%0A        for(int i = 0; i %3C nums.length; i++)%7B%0A            if(i == 0) sums%5Bi%5D = nums%5Bi%5D;%0A            else sums%5Bi%5D = sums%5Bi-1%5D + nums%5Bi%5D;%0A            if(sums%5Bi%5D == k) max = i+1;//then this one must be the max%0A        %7D%0A        CommonUtils.printArray(sums);%0A        //do computation for each possible subarray of sums and find the max length%0A        return max;%0A    %7D%0A    %0A    public static void main(String...args)%7B%0A        //correct answer is 4%0A//        int%5B%5D nums = new int%5B%5D%7B1, -1, 5, -2, 3%7D;%0A//        int k = 3;%0A        %0A        //correct answer is 2%0A        int%5B%5D nums = new int%5B%5D%7B-2, -1, 2, 1%7D;%0A        int k = 1;%0A        maxSubArrayLen_On2_solution(nums, k);%0A    %7D%0A    %0A%7D

maximum size subarray sum equals k