HardPro challengePythonJavaScriptTypeScript
Min-Heap Priority Queue
BackendData StructuresAlgorithms
Implement min-heap with push and pop.solve(ops) runs operations: ['push', n] or ['pop'] (returns popped value or null).
Returns array of pop results.
Sample tests
Test #1Pops min first
Input: [[["push",5],["push",3],["push",8],["pop"],["pop"]]]
Output: [3,5]
Test #2Empty pop
Input: [[["pop"]]]
Output: [null]
Test #3Single
Input: [[["push",1],["pop"]]]
Output: [1]
Test #4Sort via heap
Input: [[["push",4],["push",1],["push",3],["push",2],["pop"],["pop"],["pop"],["pop"]]]
Output: [1,2,3,4]
Test #5Interleaved
Input: [[["push",10],["push",5],["pop"],["push",3],["pop"]]]
Output: [5,3]