Score-Rotating Movie Playlist
Problem statement
Maintain a movie playlist with mutable integer scores. Process an ordered batch of operations:
["GET"]returns the highest-scored movie that has not yet been returned in the current cycle.["UPDATE", movie, score]replaces an existing movie's score and returns nothing.
Break score ties by lexicographically smaller movie title. After every movie has been returned once, the next GET starts a new cycle in which all movies are eligible again. An update changes ordering immediately but does not make a movie eligible again inside a cycle where it was already returned.
Return the titles produced by the GET operations in order.
Function
rotateMoviePlaylist(movies: String[], scores: int[], operations: String[][]) → String[]Examples
Example 1
movies = ["A","B","C"]scores = [9,7,8]operations = [["GET"],["GET"],["GET"],["GET"]]return = ["A","C","B","A"]Every movie appears once before the cycle resets.
Example 2
movies = ["A","B","C"]scores = [5,4,3]operations = [["GET"],["UPDATE","C","10"],["UPDATE","A","20"],["GET"],["GET"],["GET"]]return = ["A","C","B","A"]A remains exhausted despite its update; C moves ahead of B. A becomes eligible when the next cycle begins.
Example 3
movies = ["Beta","Alpha"]scores = [4,4]operations = [["GET"],["GET"]]return = ["Alpha","Beta"]Lexicographic order breaks equal-score ties.
Constraints
1 <= movies.length == scores.length <= 100000.- Movie titles are unique non-empty ASCII strings of length at most
100. -10^9 <= score <= 10^9.0 <= operations.length <= 200000.- Every update names an existing movie and every operation has the stated shape.