-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGFGDistinctCharacter.java
54 lines (46 loc) · 1.16 KB
/
GFGDistinctCharacter.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package data.structure;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class GFGDistinctCharacter {
public static void main(String args[]) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
String str1 = br.readLine();
String array[] = new String[str1.length()];
for( int i = 0 ; i<array.length ;i++)
array[i] ="";
int k = 0 ;
for( int i = 0; i<str1.length();i++)
{
if(!isContains(array[k],str1.charAt(i)))
{
array[k] += str1.charAt(i);
}
else
{
i=i-1;
array[++k] +=str1.charAt(i);
}
}
int max = 0 ;
for( int i = 0 ;i<array.length ;i++)
{
if(max < array[i].length())
max = array[i].length();
}
System.out.println(max);
}
}
private static boolean isContains(String str,char c) {
if(str.length() == 0)
return false;
for(int i = 0 ; i < str.length() ; i++)
{
if(str.charAt(i) == c)
return true;
}
return false;
}
}