I have tried my code but is not working for all the test cases
What is missing, plz do check
import java.util.*;
public class Main
{
public static ArrayList per(String s)
{
if(s.length()==0)
{
ArrayList q=new ArrayList<>();
q.add("");
return q;
}
char ch=s.charAt(0);
String s1=s.substring(1);
ArrayList fr=new ArrayList<>();
ArrayList mr=per(s1);
for(int i=0;i<mr.size();i++)
{
s1=mr.get(i)+ch;
if(!fr.contains(s1))
fr.add(s1);
s1=ch+mr.get(i);
if(!fr.contains(s1))
fr.add(s1);
}
Collections.sort(fr);
return fr;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
for(String q : per(s))
System.out.println(q);
}
}