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.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].
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.
songs=3, length=3, gap=0 → 6
songs=2, length=4, gap=1
2
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.