-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
36 lines (27 loc) · 861 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
29
30
31
32
import java.util.*;
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.HashMap;
public class test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Deque deque = new ArrayDeque<>();
HashSet<Integer> set = new HashSet<>();
int n = in.nextInt();
int m = in.nextInt();
int max = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int input = in.nextInt();
deque.add(input);
set.add(input);
if (deque.size() == m) {
if (set.size() > max)
max = set.size();
int first = (int) deque.remove();
if (!deque.contains(first))
set.remove(first);
}
}
System.out.println(max);
}
}