Dice Roll Simulation

A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.

Given an array of integers rollMax and an integer n, return the number of distinct sequences that can be obtained with exactly n rolls. Since the answer may be too large, return it modulo 10^9 + 7.

Two sequences are considered different if at least one element differs from each other.

Example 1
Inputn = 2, rollMax = [1,1,2,2,2,3]
Output34
There are 36 possible sequences without constraints, but (1,1) and (2,2) are not allowed, so the answer is 34.
Example 2
Inputn = 2, rollMax = [1,1,1,1,1,1]
Output30
With two rolls and every face allowed at most once consecutively, the six doubles are invalid, leaving 30 valid sequences.

Constraints

  • 1 <= n <= 5000
  • rollMax.length == 6
  • 1 <= rollMax[i] <= 15

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate