static void printAllkLength(char[] word1, int distinct)
{
int n=word1.length;
printAllkLengthRec(word1,"",n,distinct);
}
static void printAllkLengthRec(char[] word1, String prefix, int n, int distinct)
{
if (distinct == 0)
{
System.out.println(prefix);
return;
}
for (int i = 0; i < n; i++)
{
String newPrefix = prefix + word1[i];
printAllkLengthRec(word1, newPrefix, n, distinct-1);
}
}
I did the list for permutation but I can’t do the list for combination :/
The user will input the word and then number to be distinct, based on that to create a distinct list for combination
You can consider Set
collection which will contain only distinct values of String
type thanks to equals
/hashCode
contract.
Set<String> distinct = new HashSet<>();