Maximum Size Subarray Sum Equals k
Description
null
Solution(javascript)
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var maxSubArrayLen = function(nums, k) {
const map = {
0: -1
}
let prefixSum = 0
let max = 0
for(let i = 0; i < nums.length; i++) {
prefixSum += nums[i]
if(map[prefixSum-k] !== undefined) {
max = Math.max(i-map[prefixSum-k], max)
}
if(map[prefixSum] === undefined) {
map[prefixSum] = i
}
}
return max
};