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.
Examples
01 · Example 1
n = 4 m = 2 k = 2 return = 2
The valid selections are {0,2} and {1,3}.
02 · Example 2
n = 5 m = 3 k = 2 return = 3
Coin values are 0,1,2,3,4. The valid pairs are {0,3}, {1,2}, and {2,4}.
Constraints
1 <= n, m, k <= 10^3- Coin values are exactly
0, 1, ..., n - 1.
More Google problems
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Minimum Town Sum DifferenceOA · Seen Dec 2025
public int countDivisibleCoinSelections(int n, int m, int k) {
// write your code here
}n4
m2
k2
expected2
sign in to submit