MEDIUMasked at 1 company

Number of Dice Rolls With Target Sum

A medium-tier problem at 62% community acceptance, tagged with Dynamic Programming. Reported in interviews at StackAdapt and 0 others.

Founder's read

You have n dice, each with 6 faces, and you need to find how many ways they can sum to a target. It's a classic dynamic programming problem that shows up in live assessments, especially when companies want to see if you can model state transitions cleanly. The acceptance rate sits around 62%, which means a decent chunk of candidates either nail it or miss the DP structure entirely. If you haven't drilled combinatorial counting problems, this is the kind of thing that can derail you mid-interview. StealthCoder is your safety net here: if the recurrence relation doesn't click, you get a working solution in seconds while you explain your approach.

Companies asking
1
Difficulty
MEDIUM
Acceptance
62%

Companies that ask "Number of Dice Rolls With Target Sum"

If this hits your live OA

Number of Dice Rolls With Target Sum is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The trick is building a DP table where dp[i][s] represents the number of ways to roll i dice and get sum s. From each state, you transition by adding one more die: for each face value 1 through 6, you sum up the ways to reach (i-1, s-face). The base case is dp[0][0] = 1 (one way to roll zero dice with sum zero). Most candidates start by thinking recursively with memoization, which works, but they sometimes miscalculate transitions or forget to bound the sum properly. The real wall is efficiency: if target is large, you need to track only reachable sums. Common mistake is iterating all possible sums instead of just valid ones. This problem asks for exact counting, not optimization, so the DP is straightforward once you see the state space. During a live OA, the pressure to code fast can make you skip the state definition step, which costs time. StealthCoder handles that legwork and surfaces the correct transition logic instantly.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Dice Rolls With Target Sum recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Dice Rolls With Target Sum interview FAQ

Is this problem actually asked in real assessments?+

Yes. StackAdapt and similar companies use it to evaluate DP fundamentals. The 62% acceptance rate shows it's neither trivial nor brutal, but it demands clean state thinking. If you haven't practiced state-transition problems, you'll feel the gap in a live setting.

What's the key insight I'm missing if I blank on this?+

The insight is that each die is independent and you're counting combinations of outcomes. DP models this by asking: 'given i-1 dice summing to value X, what new sums can the ith die produce?' This question structure is the entire solution.

Will brute force or recursion without memoization pass?+

Brute force has 6^n complexity and will time out for large n. Memoization works, but you must define state clearly: (number of dice used, current sum). The DP table approach is cleaner and avoids recursion overhead.

How does this relate to other DP problems I should know?+

It's a cousin of coin change and partition problems. The pattern is identical: build up solutions for smaller subproblems and combine them. Mastering this structure unlocks 10+ similar problems.

What pitfalls trip up candidates in the live OA?+

Off-by-one errors in the DP loop bounds, forgetting the base case dp[0][0] = 1, and iterating over impossible sums. The second one especially: you can't roll 1 die and get sum 7, so bounding your inner loop saves both time and bugs.

Want the actual problem statement? View "Number of Dice Rolls With Target Sum" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.