Number of Music Playlists - Problem
Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
- Every song is played at least once
- A song can only be played again only if
kother songs have been played
Given n, goal, and k, return the number of possible playlists that you can create. Since the answer can be very large, return it modulo 10^9 + 7.
Input & Output
Example 1 — Basic Case
$
Input:
n = 3, goal = 3, k = 1
›
Output:
6
💡 Note:
We have 3 songs and want a playlist of length 3. Each song must be played at least once, and we can't repeat a song until 1 other song has been played. Possible playlists: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1].
Example 2 — Higher K Value
$
Input:
n = 2, goal = 3, k = 0
›
Output:
6
💡 Note:
With k=0, we can repeat any song immediately. We have 2 songs, need length 3, both songs used at least once. Playlists: [1,1,2], [1,2,1], [1,2,2], [2,1,1], [2,1,2], [2,2,1].
Example 3 — Impossible Case
$
Input:
n = 2, goal = 3, k = 3
›
Output:
0
💡 Note:
With k=3, we need to play 3 other songs before repeating. But we only have 2 songs total, so it's impossible to repeat any song in a playlist of length 3.
Constraints
- 1 ≤ n ≤ 100
- 1 ≤ goal ≤ 100
- 0 ≤ k < n
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code