Problem 50 of 75

Smallest Number in Infinite Set

MediumNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You have a set containing all positive integers [1, 2, 3, …]. Implement SmallestInfiniteSet: popSmallest() removes and returns the smallest integer in the set; addBack(num) adds num back if it was removed.

addBack(2); popSmallest()=1; popSmallest()=2; popSmallest()=3; addBack(1); popSmallest()=1

Your solution runs against 1 unit tests, including edge and large-value cases.

Loading...

Test console · 1 unit tests

Submit your code to run it against all 1 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Smallest Number in Infinite Set, explainedcodestorywithMIK