LeetCode75-2336-Smallest-Number-in-Infinite-Set
🧠 Summary of Thoughts
Key Insight
We do NOT store the infinite set explicitly. Instead, we simulate it using:
- A pointer next → tracks the smallest number that has never been removed
- A min heap → stores numbers that were removed and later added back
- A set → avoids duplicates in the heap
Two Methods
- popSmallest():
- If heap is not empty → return the smallest element from heap
- Otherwise → return next and increment it
addBack(num):
Only add num to heap if:
- num < next (it was removed before) and it is not already in heap
✅ Code(Java)
1 | |
LeetCode75-2336-Smallest-Number-in-Infinite-Set
https://powersixxx.github.io/leetcode-blog/2026/04/11/LeetCode75-2336-Smallest-Number-in-Infinite-Set/