Not passing all test Cases

Could you please help me in debugging the code, as this is not passing all the test cases (although according to dry run it is running fine)

import java.util.*;
public class Main {
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s[] = new String[n];
String strin = new String();
for(int i = 0;i<n;i++){
s[i] = sc.next();
strin = strin + s[i];
}
String c[] = strin.split("");
HashSet set = new HashSet<>();
n = c.length;
for(int i = 0;i<n;i++){
if(!set.contains(c[i])){
set.add(c[i]);
}
}
System.out.print(set.size());

}

}

Could you please help in solving the doubt given above?

@manyagupta1706,
Your approach is wrong.

Input:
3
un
iq
ue
Correct output:
4
Your output:
5

Suggested approach:
1.We will solve this problem through recursion.

2.So, iterate from left to right and try every string as a starting string.

3.Keep a set of character that stores characters that have occurred till now.

4.Once,you have selected a string as a starting string,now for every other string you have 2 options:

a.To add that string(only if all its characters have not occurred before) and add its character to set of current characters.

b.To leave that string

5.Try the same for all string and finally return maximum of them.

Your approach:
You are simply taking only the unique chars in the input and printing the output. Read the question once again carefully, there are certain conditions that need to fulfilled as well. :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Could you pls help me in debugging the code?

@manyagupta1706 Please ask another doubt or reopen the doubt as it is in a closed state now.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.