Given:
- Some characters in
input
String. - An integer
N
How can I generate all possible words that has the exact length of N?
If I have input = {"a", "b", "a"}
and N=2
, then the output should be: ab,aa,ba
(without the duplicates)
I searched for this, and all I got is some algorithms that I couldn't understand rather that implement. I understand that I need to implement a recursive method, but I'm stuck at the point after the stop condition.
public void generate(String input, int length) {
if(length == 0) {
System.out.println(input);
return;
}
//Not sure about this part
String[] a = input.split("");
for(int i =0; i<a.length; i++) {
loop(input+a[i], length-1);
}
}