I have a string, now want to count the minimum number of substrings such that the letters in the substring should occur only once.
Example:
Input : cycle
Output : 2
explanation:
Possible substrings are : ('cy', 'cle') or ('c', 'ycle')
Example:
Input : aaaa
Output : 4
explanation:
Possible substrings are : ('a', 'a', 'a', 'a')
I am able to get all possible substrings but I am not able to understand how to achieve the solution for this task:
static int distinctSubString(String S) {
int count = 0;
int n = S.length();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
String s = S.substring(i, j);
System.out.println(s);
}
}
return count;
}