Ezvor

325. Maximum Size Subarray Sum Equals k

MediumArray Preparing judge… LeetCode
ArrayHash TablePrefix Sum

Hints

Hint 1
Compute the prefix sum array where psum[i] is the sum of all the elements from 0 to i.
Hint 2
At each index i, the sum of the prefix is psum[i], so we are searching for the index x where psum[x] = psum[i] - k. The subarray [x + 1, i] will be of sum k.
Hint 3
Use a hashmap to get the index x efficiently or to determine that it does not exist.