Interview Query

Combinational Dice Rolls

Start Timer

0:00:00

Upvote
7
Downvote
Save question
Mark as completed
View comments (9)
Next question

Given n dice each with m faces, write a function combinational_dice_rolls to dump all possible combinations of dice rolls. 

Bonus: Can you do it recursively?

Example 1:

Input:

n = 2
m = 2

Output:

def combinational_dice_rolls(n, m) -> [
    (1,1), (1,2), (2,1), (2,2)
]

Example 2:

Input:

n = 3
m = 2

Output:

def combinational_dice_rolls(n, m) -> [
    (1,1,1),(2,1,1),(1,2,1),(1,1,2),
    (2,2,1),(1,2,2),(2,1,2),(2,2,2)
]
.
.
.
.
.


Comments

Loading comments.