BudiBadu Logo
00:00

Festival Glow Step Combinations

Dynamic Programming Easy 4 views

The festival installs a glowing ramp of length n boards, and performers may ascend the ramp using steps from a curated list of sizes. To keep the choreography smooth, the size of each step taken must be at least as large as the previous step—no sudden backward pacing allowed. The troupe wants to know how many distinct nondecreasing step sequences reach the ramp's end exactly, so they can program matching lighting arcs and coordinate live musicians.

You receive n and a list of allowed positive step sizes. Steps may repeat, but the sequence must be nondecreasing and sum precisely to n. Return the number of valid sequences modulo 1_000_000_007 using dynamic programming that progresses through the ramp while tracking the last step size; if n is zero, count the empty sequence as one calm ascent. Avoid modifying the original list so the logistics team can reuse it for other rehearsals.

Example 1:

Input: n = 4, steps = [1,2]
Output: 3
Explanation: Valid sequences are [1,1,1,1], [1,1,2], and [2,2].

Example 2:

Input: n = 3, steps = [1,3]
Output: 2
Explanation: Sequences [1,1,1] and [3] satisfy the nondecreasing rule.

Example 3:

Input: n = 5, steps = [2]
Output: 0
Explanation: No combination of nondecreasing steps sums to 5.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Festival Glow Step Combinations

Dynamic Programming Easy 4 views

The festival installs a glowing ramp of length n boards, and performers may ascend the ramp using steps from a curated list of sizes. To keep the choreography smooth, the size of each step taken must be at least as large as the previous step—no sudden backward pacing allowed. The troupe wants to know how many distinct nondecreasing step sequences reach the ramp's end exactly, so they can program matching lighting arcs and coordinate live musicians.

You receive n and a list of allowed positive step sizes. Steps may repeat, but the sequence must be nondecreasing and sum precisely to n. Return the number of valid sequences modulo 1_000_000_007 using dynamic programming that progresses through the ramp while tracking the last step size; if n is zero, count the empty sequence as one calm ascent. Avoid modifying the original list so the logistics team can reuse it for other rehearsals.

Example 1:

Input: n = 4, steps = [1,2]
Output: 3
Explanation: Valid sequences are [1,1,1,1], [1,1,2], and [2,2].

Example 2:

Input: n = 3, steps = [1,3]
Output: 2
Explanation: Sequences [1,1,1] and [3] satisfy the nondecreasing rule.

Example 3:

Input: n = 5, steps = [2]
Output: 0
Explanation: No combination of nondecreasing steps sums to 5.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.