Problem · Dynamic Programming

Dice Roll Simulation

Learn this problem
HardAtlassian logoAtlassianFULLTIMEOA

Problem statement

Roll a six-sided die exactly n times. Face i + 1 may not appear more than rollMax[i] times consecutively.

Return the number of distinct valid roll sequences modulo 1,000,000,007.

Function

dieSimulator(n: int, rollMax: int[]) → int

Examples

Example 1

n = 2rollMax = [1,1,2,2,2,3]return = 34

Of the 36 length-two sequences, only 11 and 22 violate their run limits.

Constraints

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

More Atlassian problems

drafts saved locally
public int dieSimulator(int n, int[] rollMax) {
  // Write your code here.
}
n2
rollMax[1,1,2,2,2,3]
expected34
checking account