Practice/Google/Leetcode 920. Number of Music Playlists
CodingMust
You are building a music streaming application that needs to generate concert playlists. A valid playlist must satisfy these rules:
goal songsn distinct songs to choose fromn songs must appear in the playlist at least oncek other distinct songs have been playedYour task is to count how many different valid playlists can be created following these rules.
Since the answer can be very large, return it modulo 10^9 + 7.
goal songsn distinct songs at least oncek different songs have been played10^9 + 71 <= k < n <= goal <= 100Example 1:
Input: n = 3, goal = 3, k = 1 Output: 6 Explanation: With 3 songs \{A, B, C\} and a playlist of length 3, every song appears exactly once. Since k=1, we cannot replay immediately. This is simply all permutations: ABC, ACB, BAC, BCA, CAB, CBA = 6 playlists.
Example 2:
Input: n = 2, goal = 3, k = 0 Output: 6 Explanation: With songs \{A, B\} and playlist length 3, we need to use both songs but one will repeat. Since k=0, songs can be played consecutively. Valid playlists: AAB, ABA, ABB, BAA, BAB, BBA = 6 playlists.
Example 3:
Input: n = 2, goal = 3, k = 1 Output: 2 Explanation: With k=1, we must play a different song before replaying. Valid patterns: ABA, BAB = 2 playlists.