- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
30 lines (26 loc) · 903 Bytes
/
Copy pathSolution.java
File metadata and controls
30 lines (26 loc) · 903 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
30
importjava.util.ArrayDeque;
importjava.util.HashSet;
importjava.util.Scanner;
importjava.util.Set;
publicclassSolution {
privatestaticfinalArrayDeque<Integer> deque = newArrayDeque<>();
privatestaticfinalSet<Integer> set = newHashSet<>();
publicstaticvoidmain(String[] args) {
intmax = Integer.MIN_VALUE;
try (Scannersc = newScanner(System.in)) {
intn = sc.nextInt();
intm = sc.nextInt();
for (inti = 0; i < n; i++) {
intnum = sc.nextInt();
deque.add(num);
set.add(num);
if (deque.size() == m) {
max = Math.max(max, set.size());
intfirst = deque.remove();
if (!deque.contains(first)) set.remove(first);
}
}
}
System.out.println(max);
}
}