Your question is Priority Queue Implementation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement a priority queue in a coding environment.
Implement a min-priority queue using a binary heap. Each operation is represented as a list: ['push', priority, value], ['peek'], or ['pop']. Lower priorities are removed first, and values with equal priorities must be returned in insertion order. Return the values produced by peek and pop; return None when either operation is performed on an empty queue.
Input: a list of valid operations. Output: a list containing the results of all peek and pop operations.
Example: [['push', 2, 'a'], ['push', 1, 'b'], ['pop'], ['peek']] returns ['b', 'a'].
def priority_queue(operations):