Leetcode 1016 Solution
This article provides solution to leetcode question 1016 (subarray-sums-divisible-by-k)
Access this page by simply typing in "lcs 1016" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/subarray-sums-divisible-by-k
Solution
class Solution:
def subarraysDivByK(self, A: List[int], K: int) -> int:
m = [0] * K
m[0] = 1
s = 0
for a in A:
s += a
m[s % K] += 1
return int(sum([v * (v - 1) / 2 for v in m]))