Looping Movie Playlist
Asked at Netflix
Reported by the problem's creator, not verified
A Playlist is built from a list of [movie_id, score] pairs with distinct ids. movie_id is a non-empty string of lowercase letters and score is an integer. A higher score plays first; among equal scores the smaller id (by string comparison) plays first.
A loop is one pass in which every movie currently in the playlist is served exactly once. A loop ends only when next() finds that every movie has already been served in it; that same call starts a new loop in which every movie is unserved again.
Examples
Example 1
Input: init =
[[["a",3],["b",5],["c",5],["d",1],["e",3]]], operations =[["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]],["next",[]]]Output:
["b","c","a","e","d","b","c","a","e","d","b"]Explanation:
bandctie at score 5, so the smaller idbgoes first; thenaandetie at 3, soagoes first. Afterdevery movie is served, so the sixth call starts a new loop and servesbagain.