Leetcode Problem 2102. Sequentially Ordinal Rank Tracker

2102. Sequentially Ordinal Rank Tracker

Leetcode Solutions

Using Two Heaps (Min Heap and Max Heap)

  1. Initialize two heaps: upperPart (min heap) and lowerPart (max heap).
  2. When add(name, score) is called: a. If upperPart is not empty, compare the new location with the top of upperPart. b. If the new location is better, pop the top of upperPart, push it to lowerPart, and insert the new location into upperPart. c. If the new location is not better, push it to lowerPart.
  3. When get() is called: a. Pop the top of lowerPart and push it to upperPart. b. Return the name of the new top of upperPart.
UML Thumbnail

Using SortedList from sortedcontainers

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...