Number of Music Playlists

HardDynamic Programming2d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You own n distinct songs and want a playlist of exactly goal tracks (songs may repeat). The playlist must satisfy both rules: - every one of the n songs appears at least once, and - a song may be played again only after at least k **other** songs have been played since its previous play. Return the number of different playlists (ordered track sequences) modulo 10^9 + 7.

Examples

Input: n = 3, goal = 3, k = 1
Output: 6
Every ordering of the three songs: 3! = 6.
Input: n = 2, goal = 3, k = 0
Output: 6
[1,1,2], [1,2,1], [2,1,1], [2,2,1], [2,1,2], [1,2,2].
Input: n = 2, goal = 3, k = 1
Output: 2
Only [1,2,1] and [2,1,2].

Constraints

  • 0 <= k < n <= goal <= 100

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 2d dp problems