forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.java
28 lines (24 loc) · 890 Bytes
/
solution.java
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
28
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//Using priority queue for heap implementation because priority queue is built on min-heap.
PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
for(int i = 0; i < n; i++) {
int q = sc.nextInt();
switch(q) {
case 1 :
pq.add(sc.nextInt()); //Element has been added.
break;
case 2 :
pq.remove(sc.nextInt()); //Given element will be removed.
break;
case 3 :
System.out.println(pq.peek()); //Peek is used to see the top of min-heap.
break;
}
}
}
}