-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoNotBeDistracted.java
More file actions
49 lines (44 loc) · 1.21 KB
/
DoNotBeDistracted.java
File metadata and controls
49 lines (44 loc) · 1.21 KB
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
41
42
43
44
45
46
47
48
49
import java.util.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class DoNotBeDistracted {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0)
{
int n=sc.nextInt();
char ch[]=sc.next().toCharArray();
List<Character>s=new ArrayList<>();
int j=0;
for(int i=0;i<n;i++)
{
s.add(ch[i]);
j=i;
if(ch[i]==ch[j])
{
while(i<n&&j<n&&ch[i]==ch[j])
{
j++;
}
i=j-1;
}
}
boolean found=false;
for(int i=0;i<s.size();i++)
{
if(s.contains(s.get(i))&&s.indexOf(s.get(i))!=i&&s.indexOf(s.get(i))!=-1)
{
found=true;
break;
}
}
if(found)
System.out.println("NO");
else
System.out.println("YES");
}
sc.close();
}
}