Looping Movie Playlist
NetflixOnsiteMedium
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.
Part 1: Serve in score order
Implement next(). It returns the id of the unserved movie with the highest score, or the smallest id among ties, and marks it served in the current loop. If every movie is already served, that call first starts a new loop where every movie is unserved, then serves from it as usual. If the playlist has no movies, return None.
- Example 1
- 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"]
Why:
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.
Constraints
0 <= len(movies) <= 10^41 <= len(operations) <= 10^4-10^9 <= score <= 10^91 <= len(movie_id) <= 10movie_idconsists of lowercase letters