The problem. Given an array of integers nums and an integer k, return the number of (non-empty) subarrays whose sum is divisible by k — a sum of 0, k, −k, 2k … all count.
nums = [4, 5, 0, -2, -3, 1], k = 5 -> 7
nums = [5], k = 9 -> 0
nums = [-1, 2, 9], k = 2 -> 2 ([2] and [-1, 2, 9])Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson