Back to Practice Dashboard
DSA SectionEasy

Priority Queue

Learn how to solve the 'Priority Queue' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function execute_priority_queue(operations) that simulates a Min-Priority Queue. The input is a list of tuples operations of the form ("insert", val) or ("extract_min",). Return the list of extracted minimum values.

Constraints
  • 0 <= len(operations) <= 1000

Examples

Example 1
Input
operations = [("insert", 5), ("insert", 2), ("insert", 8), ("extract_min",), ("extract_min",)]
Output
[2, 5]
Explanation

Insert 5, 2, 8. First extract returns 2. Second extract returns 5.

Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor