Implement Min Heap
Mediumjavapythonccppjavascript
Implement a Min Heap that supports inserting a value, reading the minimum, and removing the minimum.
Input Format
The first line contains an integer Q. Each of the next Q lines is one of: insert X — add integer X getMin — report the minimum extractMin — remove and report the minimum
Output Format
For each getMin print the current minimum (or -1 if the heap is empty). For each extractMin print the removed minimum (or -1 if the heap is empty). One value per line.
Example 1
Input
4 insert 5 insert 2 insert 8 getMin
Output
2
Explanation: The smallest value is always kept at the root.
- 1 <= Q <= 100000
- -1000000000 <= X <= 1000000000