Sequentially Ordinal Rank Tracker
expert · 1160 · lc hard +32 · 61.5% accepted · 407 likes · top 62%
Description
A scenic location is described by its name and attractiveness score, where name is a unique string and score is an integer. Locations are ranked from best to worst: higher score means better rank. If two locations share the same score, the one with the lexicographically smaller name ranks higher.
You are building a tracker that starts with no locations and supports two operations:
- Adding scenic locations one at a time.
- Querying the ith best location, where i equals the total number of times the system has been queried so far (including the current query).
The test data guarantees that the number of queries never exceeds the number of added locations.
Implement the SORTracker class:
- SORTracker() Initializes the tracker system.
- void add(string name, int score) Adds a scenic location with name and score to the system.
- string get() Queries and returns the ith best location, where i is the number of times this method has been invoked (including this invocation).
Example 1:
Example 2:
Code