LeetCode 920, Hard. Topics: Math, Dynamic Programming, Combinatorics. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:
Problem
Your music player contains <code>n</code> different songs. You want to listen to <code>goal</code> songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that:
<ul>
<li>Every song is played <strong>at least once</strong>.</li>
<li>A song can only be played again only if <code>k</code> other songs have been played.</li>
</ul>
<p>Given <code>n</code>, <code>goal</code>, and <code>k</code>, return <em>the number of possible playlists that you can create</em>. Since the answer can be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
Examples
Constraints
- 0 <= k < n <= goal <= 100
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026