Implement Max Heap
Mediumjavapythonccppjavascript
Implement a Max Heap that supports inserting a value, reading the maximum, and removing the maximum.
Input Format
The first line contains an integer Q. Each of the next Q lines is one of: insert X, getMax, extractMax.
Output Format
For each getMax print the current maximum (or -1 if empty). For each extractMax print the removed maximum (or -1 if empty). One value per line.
Example 1
Input
4 insert 5 insert 9 insert 2 getMax
Output
9
Explanation: The largest inserted value is stored at the root.
- 1 <= Q <= 100000
- -1000000000 <= X <= 1000000000