Ctrl K

Dice With Streak Caps

Hard
An electronic die produces numbers from 1 to 6, with one restriction: face i can never come up more than max_streak[i − 1] times in a row. How many different sequences of exactly rolls throws can this die produce? Two sequences differ if they hold different numbers in at least one position. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
rolls=2, max_streak=[2, 2, 2, 1, 2, 1] → 34

Without limits there are 36 pairs. Only 4, 4 and 6, 6 are banned, since those faces cannot come up twice in a row. That leaves 34.

Example 2
rolls=3, max_streak=[1, 1, 1, 1, 1, 1] → 150

Each throw must differ from the one before it: 6 · 5 · 5 = 150.

Constraints
  • 1 ≤ rolls ≤ 5000
  • len(max_streak) = 6
  • 1 ≤ max_streak[i] ≤ 15
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWater Between Walls HardBiggest Solid Panel Block HardProfit From Two Trades HardEvery Way to Space the Words HardCrossing the Cave Hard
loading Python…
Input
rolls=2, max_streak=[2, 2, 2, 1, 2, 1]
Expected
34

Run checks the first 3 tests in your browser. Submit checks all 43 tests on the server, hidden ones included.