Skip to content

#2336 - Smallest Number in Infinite Set

MediumHeap / Priority Queue
Open on LeetCode

You have a set containing all positive integers [1, 2, 3, …]. Implement the SmallestInfiniteSet class:

  • popSmallest() – removes and returns the smallest integer in the set.
  • addBack(num) – adds num back into the set if it is not already present.
InputOutput
OperationsOutput
popSmallest(), popSmallest(), popSmallest(), addBack(1), popSmallest(), popSmallest(), popSmallest()[1, 2, 3, 1, 4, 5, 6]

Released under the MIT License.