Ctrl K

Radio Show Without Quick Repeats

Hard
A radio host is planning a show of exactly length tracks. The library holds songs distinct tracks, and the show must follow two rules: - every track in the library plays at least once; - a track may be scheduled again only if at least gap other tracks have played since it last aired. How many different shows can be put together? Two shows differ if some position holds a different track. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
songs=2, length=4, gap=1 → 2

A track may repeat only after one other track, so the two must alternate: [1, 2, 1, 2] and [2, 1, 2, 1].

Example 2
songs=3, length=4, gap=2 → 6

The first three slots are any permutation of the three tracks (6 options), and the fourth can only be the first track, since exactly two others have played since it.

Example 3
songs=3, length=3, gap=0 → 6
Constraints
  • 0 ≤ gap < songs ≤ length ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTasters and the Spoiled Cask HardParcel Run Orders HardA Fair Split of Colored Beads HardOther Orders for the Same Search Tree HardK-th Route in Alphabetical Order Hard
loading Python…
Input
songs=2, length=4, gap=1
Expected
2

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