Skip to content

Practice Sequentially Ordinal Rank Tracker

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2102
LeetCode Problem

Sequentially Ordinal Rank Tracker

Problem Statement

SORTracker starts empty. add(name,score) adds a uniquely named location. Higher scores rank first, with lexicographically smaller names breaking ties. The ith get() returns the ith best location among all entries present at that moment. Later insertions may change ranks, so the same name can be returned on multiple get calls. Practice approach: Maintain two heaps around the number of queries already served: the best i locations and the remaining locations. Keep the worst of the best partition at its root. Rebalance after insertion and grow the partition on get. An order-statistics tree also supports rank selection.

Source: Sequentially Ordinal Rank Tracker on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["SORTracker","add","add","get","add","get","get"]
[[],["beta",3],["alpha",3],[],["gamma",5],[],[]]
Output
[null,null,null,"alpha",null,"alpha","beta"]
Explanation

Alpha initially ranks first by the name tie-break. After Gamma is added, Alpha ranks second and is returned again.

Constraints

Names are distinct lowercase strings of length 1 to 10.
1 <= score <= 10^5
get calls never exceed add calls.
At most 4 * 10^4 total calls.

Related LeetCode Problems

Practice more problems similar to Sequentially Ordinal Rank Tracker.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.