Skip to the code
cf.
+25 XP

#569 Ways to Roll a Board Game Total

medium

A browser board game rolls dice dice, each with faces numbered 1 to faces. The dice are different colors, so rolling 1 then 6 is different from 6 then 1.

Write countRolls(dice, faces, target) that returns how many rolls add up to exactly target, modulo 1000000007.

Example 1

Input: dice = 2, faces = 6, target = 7
Output: 6

1+6, 2+5, 3+4, 4+3, 5+2, and 6+1.

Example 2

Input: dice = 1, faces = 6, target = 3
Output: 1

One die showing 3.

Constraints

  • 1 <= dice, faces <= 30
  • 1 <= target <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).