Initially this seemed like a no brainer, but the more I am trying to do this, the more I am getting stuck.
I am looking to create a recursive method that will take a string and output combination with dots as below:
input: test
output:
test
t.est
te.st
tes.t
t.es.t
te.s.t
t.e.s.t
t.e.st
you get the idea... I need all permutations of dots between the characters. But two dots should not appear together and dot should not be the first or the last character.
The code I have written is:
public final class Main{
public static void main(String[] args) throws Exception{
recurse ("test");
}
public static void recurse(String str){
recurse("",str);
}
public static void recurse (String pre, String str){
if(str.length() > 1){
recurse(pre+str.substring(0,1)+".",str.substring(1));
}
System.out.println(pre+str);
}
}
But, I can't get my head around it. What change should I do?
Just for the sake of clarification I got the idea from https://medium.com/@JakeCooper/so-nice-i-did-it-twice-hacking-the-oneplus-reservation-system-again-2e8226c45f9a, but I do not have any intention of hacking the invite system.
str.length() <= 1.oneplus2invite hack? :P