Solved LeetCode program · 739 of 1,000
#0974 · Subarray Sums Divisible by K
Original English source
The numbers is a list of 4, 5, 0, -2, -3, 1. The divisor is 5. The counts is a list of 5 zeros. Set item 0 of counts to 1. The total is 0. The ways is 0.
For each value in numbers.
Add value to total. The rem is total modulo divisor. If rem is less than 0, add divisor to rem. Increase ways by item rem of counts. Increase item rem of counts by 1.
Show ways.
Expected stdout
7