MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / checkSubarraySum

Function checkSubarraySum

javascript/0523-continuous-subarray-sum.js:9–24  ·  view source on GitHub ↗
(arr, k)

Source from the content-addressed store, hash-verified

7 * @return {boolean}
8 */
9var checkSubarraySum = function (arr, k) {
10 let sum = 0;
11 const remainderMap = new Map([[0, -1]]);
12
13 for (let i = 0; i < arr.length; i++) {
14 sum += arr[i];
15 if (remainderMap.has(sum % k) && i - remainderMap.get(sum % k) > 1) {
16 return true;
17 }
18 if (!remainderMap.has(sum % k)) {
19 remainderMap.set(sum % k, i);
20 }
21 }
22
23 return false;
24};

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected