Ctrl K

Running Sum Waves

Medium
A row of length cells starts with a 1 in every cell. Every second a "wave" passes: all cells are replaced at once by the sum of the cell itself and every cell to its left. So the first cell never changes. Return the value of the last cell after waves waves, modulo 10⁹ + 7.
Example 1
length=3, waves=4 → 15

[1, 1, 1] → [1, 2, 3] → [1, 3, 6] → [1, 4, 10] → [1, 5, 15], so the last value is 15.

Example 2
length=1, waves=7 → 1

A single cell always stays at 1.

Example 3
length=5, waves=2 → 15

[1, 1, 1, 1, 1] → [1, 2, 3, 4, 5] → [1, 3, 6, 10, 15].

Constraints
  • 1 ≤ length ≤ 1000
  • 1 ≤ waves ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTop of the Digit Pyramid MediumSplit Into a Climb and a Descent HardSplit Into a Climb and a Descent: Large Values HardPair GCDs by Sorted Position HardA Stretch Divisible by k Medium
loading Python…
Input
length=3, waves=4
Expected
15

Run checks the first 3 tests in your browser. Submit checks all 66 tests on the server, hidden ones included.