FastPrepNumber of Dice Rolls With Target Sum

Number of Dice Rolls With Target Sum

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Roll dice identical dice, each with faces numbered from 1 through faces. Return the number of ordered outcomes whose sum equals target, modulo 1,000,000,007.

Function

numRollsToTarget(dice: int, faces: int, target: int) → int

Examples

Example 1

dice = 2faces = 6target = 7return = 6

The ordered pairs are (1,6) through (6,1).

Constraints

  • 1 <= dice, faces <= 30.
  • 1 <= target <= 1000.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int numRollsToTarget(int dice, int faces, int target) {
  // Write your code here.
}
dice2
faces6
target7
expected6
Checking account…