-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_Dequeue.java
More file actions
29 lines (26 loc) · 787 Bytes
/
Java_Dequeue.java
File metadata and controls
29 lines (26 loc) · 787 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
28
29
import java.util.*;
public class JavaDequeue {
// Mohajit Paul 20BCE10630
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Deque<Integer> dq = new ArrayDeque<Integer>();
HashSet<Integer> s = new HashSet<Integer>();
int n = sc.nextInt();
int m = sc.nextInt();
int max = 0;
for (int i = 0; i < n; i++) {
int tmp = sc.nextInt();
dq.add(tmp);
s.add(tmp);
if (dq.size() == m) {
max = Math.max(s.size(), max);
int item = dq.remove();
if (!dq.contains(item)) {
s.remove(item);
}
}
}
System.out.println(max);
sc.close();
}
}