Implement a Heap Priority Queue
Problem statement
Implement a min-priority queue of integers without using a built-in priority-queue or heap data structure. Process operations from left to right:
PUSHinsertsvalues[i].PEEKreturns the current minimum without removing it.POPremoves and returns the current minimum.
Collect and return every value produced by PEEK or POP, in operation order. Every observation occurs while the queue is nonempty. Equal values are allowed; values[i] is ignored for observation operations.
Function
runPriorityQueue(operations: String[], values: int[]) → int[]Examples
Example 1
operations = ["PUSH","PUSH","PEEK","POP","PEEK"]values = [5,2,0,0,0]return = [2,2,5]The minimum after both insertions is 2. POP returns and removes 2, leaving 5.
Example 2
operations = ["PUSH","PUSH","PUSH","POP","POP","POP"]values = [3,3,1,0,0,0]return = [1,3,3]Repeated values remain separate queue entries and are removed in nondecreasing priority order.
Example 3
operations = ["PUSH","PEEK","PUSH","PEEK"]values = [-4,0,-7,0]return = [-4,-7]The second insertion becomes the new minimum.
Constraints
1 <= operations.length == values.length <= 200000.- Each operation is
PUSH,PEEK, orPOP. - Every
PEEKandPOPoccurs when the queue is nonempty. - Each inserted value is a signed 32-bit integer.