genres. You build a playlist by striking out any tracks you like from the queue; the rest keep their original order.
A genre change is a pair of neighbouring tracks in the playlist with different genres. The listener tolerates at most switches changes.
Return the largest possible number of tracks in such a playlist.genres=[4, 4, 7, 4, 7, 7], switches=1 → 5
Take 4, 4, 4, 7, 7 (skipping the first 7): one genre change. All six tracks would mean three changes.
genres=[3, 8, 3, 8], switches=0 → 2
With no changes allowed, only tracks of one genre fit: the two 3s or the two 8s.
genres=[9], switches=0 → 1
genres=[4, 4, 7, 4, 7, 7], switches=1
5
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.