Dynamic Programming pattern
Dice Combinations
Count the number of ways to reach the sum n by throwing a six-sided die one or more times. Each throw yields a value from 1 to 6, and order matters, for n = 3 the four ways are 1+1+1, 1+2, 2+1 and 3. Return the count modulo 10^9+7. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 377
- Medium
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Dynamic ProgrammingLeetCode 377
Medium
From the first idea to the best one
- 01 Brute force · recursion O(6ⁿ)O(n) space
- 02 Optimized · tabulation O(n)O(n) space
What you will learn
- How to read Dice Combinations and spot the dynamic programming pattern in it
- Brute force · recursion: O(6ⁿ) time, O(n) space
- Optimized · tabulation: O(n) time, O(n) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Dynamic Programming
See Dice Combinations run, step by step
Sign in and this page opens on the animation, with all 18 Dynamic Programming problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.