Skip to content
CampusEduX

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.

Related Problems

  • Implement Min Heap
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Merge K Sorted Arrays
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • K Largest Elements
    Easy · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...