Dynamic Person Rankings
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Dynamic Fixed-K Score LeaderboardCoinbase · ONSITE INTERVIEWCoinbase interview questions
- Volunteer Awards: Totals Divisible by KNutanix · ONSITE INTERVIEWNutanix interview questions
- Crossed User Pairs on One DateRippling · ONSITE INTERVIEWRippling interview questions
- Dynamic Fixed-K Score LeaderboardAnchorage · PHONE SCREEN
- Segment QueriesTikTok · OATikTok interview questions
- Colored Rooted TreeRubrik · ONSITE INTERVIEWRubrik interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- LFU CacheAmazon · ONSITE INTERVIEW
- Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions