Radio rotation audit
EasyOnline Assessment
Audit a radio station's playlist log and report every song that breaks the artist-separation rule.
log lists what went out on air, in order. Each entry is either the text "[ad]" (an ad break) or the artist credit of one song. A credit holds one or more artist names joined by " & ", for example "Nova Reyes & Kite" credits two artists. Names are compared ignoring letter case, so "KITE" and "Kite" are the same artist.
The station's rule: an artist must not be heard again until at least gap other songs have been played since their last appearance. In other words, a song is a violation if any artist credited on it was credited on any of the previous gap songs. Ad breaks are not songs: they do not count toward the gap and they do not reset anything. A song that is a violation still counts as having been played, so it also blocks the artists credited on it for the songs that follow.
Input: log, the on-air entries in order, and the separation gap.
Output: a list of the 1-based positions in log (ads occupy positions too) of every violating song, in increasing order. Return an empty list if there are none, including when gap is 0 or the log is empty.
Example 1
- Input:
- [["Kite","Dune","[ad]","Kite","Nova Reyes","Dune"],2]
- Output:
- [4]
- Explanation
- Songs are numbered 1, 2, 3 ... ignoring the ad. With
gap = 2, the second "Kite" (log position 4, song 3) is checked against the previous 2 songs, "Kite" and "Dune", so it is a violation. The ad at position 3 is not a song and does not help. Later "Dune" (position 6, song 5) is checked against "Kite" and "Nova Reyes", so it is fine. The answer is[4].
Example 2
- Input:
- [["Kite","Dune","nova reyes & Kite","KITE","Ode"],3]
- Output:
- [3,4]
- Explanation
- Credits are split into names and compared ignoring case. With
gap = 3, position 3 ("nova reyes & Kite") shares "Kite" with position 1, a violation. Position 4 ("KITE") repeats "Kite" from positions 1 and 3; position 3 was itself a violation but still counts as played. Position 5 ("Ode") is new. The answer is[3, 4].
Example 3
- Input:
- [["Kite","Kite","Kite"],0]
- Output:
- []
- Explanation
- With
gap = 0no song is checked against any earlier song, so nothing is flagged and the answer is[].
Constraints
0 <= log.length <= 2,000- every entry is
"[ad]"or an artist credit of one or more artist names joined by" & " - an artist name is 1 to 30 letters and spaces, with no leading or trailing space
0 <= gap <= 50