Tricky permutations problem

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ArrayList a= getpermutation(sc.nextLine());
ArrayList b=replaceduplicate(a,0);
String c[]=new String[b.size()];
c=b.toArray©;
printArray©;
}
public static ArrayList getpermutation(String p)
{
if(p.length()==0)
{
ArrayList bc=new ArrayList<>();
bc.add("");
return bc;
}
ArrayList mr=new ArrayList<>();
String cs=p.substring(0, 1);
String rs=p.substring(1);
ArrayList rr=getpermutation(rs);
for(String i:rr)
{
for(int j=0;j<=i.length();j++)
{
mr.add(i.substring(0,j) + cs +i.substring(j));
}
}
return mr;
}
public static ArrayList replaceduplicate(ArrayList list,int counter)
{

    if(counter < list.size()){
        if(list.contains(list.get(counter))){
            list.remove(list.lastIndexOf(list.get(counter)));
        }
        replaceduplicate(list, ++counter);
    }
	return list;
}

public static void printArray(String []words)
{
for(int i = 0; i < words.length; ++i) {
for (int j = i + 1; j < words.length; ++j) {
if (words[i].compareTo(words[j]) > 0) {
String temp = words[i];
words[i] = words[j];
words[j] = temp;
}
}

for(int i = 0; i < words.length; i++) {
    System.out.println(words[i]);
}

}
}

this is my solution what is problem in this solution

hi @sksumitkumardiwaker

Sort the array to maintain the order of the provided answer and to remove duplicates you have check the previous element as duplicacy will be because of the similar characters.

@sksumitkumardiwaker
mark your doubt as resolved and rate me aswell

1 Like

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.