Leetcode: 2102. Sequentially Ordinal Rank Tracker
- Can we pre-process the input in a way to make easy to solve the problem? Keep the input sorted by score and name. Time complexity is \(O(n \log n)\) and space is \(O(n)\).
from sortedcontainers import SortedList class SORTracker: def __init__(self): self.loc = SortedList() self.q = 0 def add(self, name: str, score: int) -> None: self.loc.add((-score, name)) def get(self) -> str: ans = self.loc[self.q][1] self.q += 1 return ans # Your SORTracker object will be instantiated and called as such: # obj = SORTracker() # obj.add(name,score) # param_2 = obj.get()