 All Problems
Subarray Sum Divisible by K
medium
arrays
hash map
prefix sum
amazon
google
facebook

Given an integer array nums and integer k, return the number of non-empty subarrays whose sum is divisible by k.

Example 1:

Input: 4 5 0 -2 -3 1
k: 5
Output: 7

Example 2:

Input: 5
k: 9
Output: 0

Input format: Line 1: space-separated array. Line 2: k.

Output format: Count of subarrays.

Run to check your code against the sample cases, or submit to run every case