Problem
Count Divisible Coin Selections
Learn this problemProblem statement
There are n coins with values from 0 to n - 1, inclusive.
Return the number of ways to select exactly k coins such that the sum of the selected coin values is divisible by m.
Return the answer modulo 10^9 + 7.
Function
countDivisibleCoinSelections(n: int, m: int, k: int) → intExamples
Example 1
n = 4m = 2k = 2return = 2The valid selections are {0,2} and {1,3}.
Example 2
n = 5m = 3k = 2return = 3Coin values are 0,1,2,3,4. The valid pairs are {0,3}, {1,2}, and {2,4}.
Constraints
1 <= n <= 2001 <= m <= 1000 <= k <= n- Coin values are exactly
0, 1, ..., n - 1. - Return the answer modulo
10^9 + 7.
More Google problems
- Count Sortable SplitsOA · Seen Jul 2026
- Minimum Absolute SumOA · Seen Jul 2026
- Binary Matrix Top-to-Bottom ReachabilityONSITE INTERVIEW · Seen Jul 2026
- Enumerate Top-to-Bottom Grid PathsONSITE INTERVIEW · Seen Jul 2026
- Inclusive Rectangle Coverage CountsONSITE INTERVIEW · Seen Jul 2026
- Maximum Coins With Moving TokensOA · Seen Jul 2026
- Maximum Elements With a Common DigitOA · Seen Jul 2026
- Minimum-Weight Top-to-Bottom Grid PathONSITE INTERVIEW · Seen Jul 2026