2102. Sequentially Ordinal Rank Tracker
Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 62% Topics: Design, Heap (Priority Queue), Data Stream, Ordered Set
View full problem on LeetCode Reference solution (spoiler · python)
# Time: add: O(logn)
# get: O(logn)
# Space: O(n)
from sortedcontainers import SortedList
class SORTracker(object):
def __init__(self):
self.__sl = SortedList()
self.__i = 0
def add(self, name, score):
"""
:type name: str
:type score: int
:rtype: None
"""
self.__sl.add((-score, name))
def get(self):
"""
:rtype: str
"""
self.__i += 1
return self.__sl[self.__i-1][1]
Solution from kamyu104/LeetCode-Solutions · MIT