Unique Unordered Dice Outcomes
Updated
Problem statement
A die has faces labeled from 1 through faces and is rolled rolls times. Return every distinct outcome when roll order does not matter.
Represent each outcome as a nondecreasing array of face values. Return all outcomes in lexicographic order. Repeated face values are allowed. When rolls = 0, return one empty outcome.
Function
unorderedDiceOutcomes(faces: int, rolls: int) → int[][]Examples
Example 1
faces = 3rolls = 2return = [[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]Each pair is nondecreasing, so order-equivalent results such as [1,2] and [2,1] appear only once.
Example 2
faces = 2rolls = 0return = [[]]There is exactly one way to make zero rolls: the empty outcome.
Constraints
1 <= faces <= 150 <= rolls <= 10- The number of returned outcomes is at most
100000
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
- Beautiful ArrangementMathWorks · ONSITE INTERVIEWMathWorks interview questions
- First Valid Word SegmentationAmazon · ONSITE INTERVIEW
- Generate One-Two Strings with Sum NGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Distinct Palindrome PartitionsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- Find a Subset of Exactly K Elements with a Target SumJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Count and Score Distinct Hat AssignmentsRoblox · ONSITE INTERVIEWRoblox interview questions
- Partition a Card Deck into FifteensMeta · ONSITE INTERVIEWMeta interview questions
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions