You are given an initially empty Binary Min Heap and a series of queries. Your task is to implement three methods: insertKey, deleteKey, and extractMin on the Binary Min Heap, and call them as per the query given below:
Example 1
Input: Q = 6, Queries: insertKey(10) insertKey(5) insertKey(15) extractMin() deleteKey(1) extractMin()
Output: [5, 10]
Explanation: insertKey(10): The heap starts empty. After inserting 10, the heap becomes {10}. insertKey(5): Inserting 5 results in the heap {5, 10} since 5 is the smaller element. insertKey(15): Inserting 15 results in the heap {5, 10, 15}. extractMin(): The minimum element 5 is removed from the heap, leaving {10, 15}, and 5 is printed. deleteKey(1): The element at position 1 (which is 15) is removed, leaving {10}. extractMin(): The minimum element 10 is removed, and 10 is printed. The heap is now empty.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
6 1 5 1 3 1 10 3 2 3 3
3 5
6 1 10 1 5 1 15 3 2 1 3
5 10