Implement a Min-Heap with insertion, deletion, and heapify operations using a slice.
HardProblem Statement
Implement a Min-Heap with insertion, deletion, and heapify operations using a slice.
Sample Input
Insert(5); Insert(3); GetMin()
Sample Output
3
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
package main
import "fmt"
type MinHeap struct {
// Your code here
}
func main() {
heap := &MinHeap{}
heap.Insert(5)
heap.Insert(3)
heap.Insert(8)
heap.Insert(1)
fmt.Println(heap.ExtractMin()) // Expected Output: 1
fmt.Println(heap.ExtractMin()) // Expected Output: 3
}
Input
Insert(5); Insert(3); GetMin()
Expected Output
3