-
Notifications
You must be signed in to change notification settings - Fork 9
/
playlist.java
40 lines (36 loc) · 913 Bytes
/
playlist.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
33
34
35
36
37
38
39
40
import java.util.HashSet;
import java.util.Scanner;
/**
* playlist
*/
public class playlist {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] a = new int[n];
for(int k = 0; k < n; k++){
a[k] = s.nextInt();
}
int i = 0;
int j = 1;
int currL = 1;
int max = 0;
HashSet<Integer> set = new HashSet<Integer>();
set.add(a[0]);
while(i < a.length - 1 && j < a.length){
if(!set.contains(a[j])){
set.add(a[j]);
j++;
currL++;
} else {
max = Math.max(max, currL);
set.remove(a[i]);
i++;
currL--;
}
}
max = Math.max(max, currL);
System.out.println(max);
s.close();
}
}