Looping Movie Playlist

Asked at NetflixOnsite

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

  1. 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: b and c tie at score 5, so the smaller id b goes first; then a and e tie at 3, so a goes first. After d every movie is served, so the sixth call starts a new loop and serves b again.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.