Not getting the desired output

Code:
package recursion;

import java.util.ArrayList;

public class Permutation {

public static void main(String[] args) {
	System.out.println(getPermutation("abc"));
}

public static ArrayList<String> getPermutation(String str)
{
	if(str.length()==0) {
		ArrayList<String> br = new ArrayList<>();
		br.add("");
		return br;
	}
	char ch = str.charAt(0);
	String ros = str.substring(1);
	ArrayList<String> rr = getPermutation(ros);
	
	ArrayList<String> mr = new ArrayList<>();
	for(String rrs:rr)
	{
		for(int i=0;i<rrs.length();i++)
		{
			String val = rrs.substring(0,i) + ch + rrs.substring(i);
			mr.add(val);
		}
	}
	
	return mr;
}

}

Hey @bharath_gopishetti, you have an error in this line:

i can vary from 0 to <= rrs.length() as we can also append the character at the end.

So, we should use this

Hope it helps :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.