Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 865 Bytes

File metadata and controls

24 lines (18 loc) · 865 Bytes

974. Subarray Sums Divisible by K

Medium


Given an array nums of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by k.

 

Example 1:

Input: nums = [4,5,0,-2,-3,1], k = 5
Output: 7
Explanation: There are 7 subarrays with a sum divisible by k = 5:
[4, 5, 0, -2, -3, 1], [5], [5, 0], [5, 0, -2, -3], [0], [0, -2, -3], [-2, -3]

 

Note:

  1. 1 <= nums.length <= 30000
  2. -10000 <= nums[i] <= 10000
  3. 2 <= k <= 10000