Social feed~20 min2s · 256 MBtarget O((start + count) × k) time, O(k) spaceclassic twin: lc-77backtracking
A feed app has n moderators, numbered from 1. A review panel is a group of exactly k different moderators, and the order inside the group does not matter.
The number of panels is large. The team lists them in a fixed order, a page at a time.
Your team lead says: Choose moderators in increasing order. Try only moderators that leave enough later ones to fill the panel. Stop when the page is full.
Write reviewer_panels(n, k, start, count).
start to start + count - 1 of that list, counting from 0.Input: n = 4, k = 2, start = 0, count = 100
Output: [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]Each call chooses a later moderator, explores, and undoes the choice. A call with two moderators is a full panel.
| Step | Panel so far | Action |
|---|---|---|
| 1 | [1] | choose moderator 1 |
| 2 | [1, 2] | choose moderator 2 |
| 3 | [1, 2] | a full panel: save it |
| 4 | [1, 3] | choose moderator 3 |
| 5 | [1, 3] | a full panel: save it |
| 6 | [1, 4] | choose moderator 4 |
| 7 | [1, 4] | a full panel: save it |
| 8 | [2] | choose moderator 2 |
| 9 | [2, 3] | choose moderator 3 |
| 10 | [2, 3] | a full panel: save it |
| 11 | [2, 4] | choose moderator 4 |
| 12 | [2, 4] | a full panel: save it |
| 13 | [3] | choose moderator 3 |
| 14 | [3, 4] | choose moderator 4 |
| 15 | [3, 4] | a full panel: save it |
The 6 panels are the saved rows, in order.
Input: n = 6, k = 3, start = 7, count = 5
Output: [[1, 4, 5], [1, 4, 6], [1, 5, 6], [2, 3, 4], [2, 3, 5]]Six moderators make 20 panels of three. Positions 7 to 11 are the page.
Input: n = 3, k = 3, start = 0, count = 4
Output: [[1, 2, 3]]There is exactly one panel: all three moderators.
1 ≤ n ≤ 401 ≤ k ≤ n0 ≤ start ≤ 100,0001 ≤ count ≤ 100With 40 moderators and panels of 20 there are 137,846,528,820 panels. A page needs only start + count of them, at most 100,100. The recursion stops as soon as the page is full.