You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* e.g. in case of the array [23,2,6,4,7] the running sum is [23,25,31,35,42]
13
+
* e.g. in case of the array [23,2,6,4,7] and k = 6 the running sum is [23,25,31,35,42]
14
14
* and the remainders are [5,1,1,5,0].
15
15
* We got reminder 5 at index 0 and at index 3.
16
16
* That means, in between these two indexes we must have added a number which is multiple of the k.
17
17
* Hope this clarifies your doubt :)"
18
18
*/
19
19
publicbooleancheckSubarraySum(int[] nums, intk) {
20
20
Map<Integer, Integer> map = newHashMap<>();
21
-
map.put(0, -1);
21
+
map.put(0, -1);//this line is critical to mark the beginning of the prefix sum, so that next time, when we encounter a running sum of zero, we know that's the answer, see test case 11
22
22
intsum = 0;
23
23
for (inti = 0; i < nums.length; i++) {
24
24
sum += nums[i];
@@ -41,6 +41,9 @@ public boolean checkSubarraySum(int[] nums, int k) {
0 commit comments