Skip to content
CampusEduX

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.

Related Problems

  • Implement Max 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...