-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathQHEAP1.java
More file actions
27 lines (24 loc) Β· 799 Bytes
/
QHEAP1.java
File metadata and controls
27 lines (24 loc) Β· 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// https://www.hackerrank.com/challenges/qheap1/problem
package heap;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
public class QHEAP1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int queries = scanner.nextInt();
Queue<Integer> minHeap = new PriorityQueue<>();
while (queries-- > 0) {
int command = scanner.nextInt();
if (command == 1) {
int element = scanner.nextInt();
minHeap.add(element);
} else if (command == 2) {
int element = scanner.nextInt();
minHeap.remove(element);
} else {
System.out.println(minHeap.peek());
}
}
}
}