Maximum Size Subarray Sum Equals k

Problem

discuss.leetcode.com

Solution

This problem can be solved by using HashMap effectively. First, we store each sum of range from 0 to i (0 <= i < N). While we traverse the array, we check if the (sum - k) is stored in HashMap. If the number is in the map, the size of subarray that its sum equals k is i - hash.get(sum - k). This is the most important point.

Source Code