Dynamic Person Rankings
Problem statement
Process operations on a ranking of people with unique names and unique integer scores.
ADD name scoreinserts a new person.UPDATE name scorechanges an existing person's score.GET rankreturns the person at the one-based rank, where rank1is the highest score.
Every operation is valid, and scores remain unique after each update. Return one string name:score for each GET, in operation order.
Function
processRankings(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","alice","90"],["ADD","bob","70"],["GET","1"],["UPDATE","bob","95"],["GET","1"],["GET","2"]]return = ["alice:90","bob:95","alice:90"]Alice starts first. Updating Bob to 95 moves him above Alice.
Example 2
operations = [["ADD","x","-5"],["ADD","y","10"],["ADD","z","0"],["GET","2"]]return = ["z:0"]Scores in descending order are 10,0,-5.
Example 3
operations = []return = []No operations produce no rank-query results.
Constraints
0 <= operations.length <= 200000.- Names contain
1through20letters or digits. - Scores are signed 32-bit integers.
GETranks are valid for the current number of people.