Question bank › Recursion
Dsa Recursion Medium

Combinations of Dice Rolls

You have a six-sided die, and you want to find all unique combinations of die rolls that add up to a given target sum. Write a function that prints all unique combinations of rolls that yield the target sum, with each combination sorted in ascending order. Each combination can use any number of dice rolls, but must not use the same face more than once per roll. For example, given a target sum of 7, the output should include combinations like: - [1, 2, 4] - [1, 3, 3] - [2, 5] Input format: - A single integer n (1 <= n <= 30), the target sum. Output format: - Print each combination on a new line with elements in ascending order. Example: Input: 7 Output: [1, 2, 4] [1, 3, 3] [2, 5]

Key concepts

recursioncombinatoricsbacktracking

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.