Could you please help me over this ? i am unable to pass test cases

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
// String str = “abc”;
ArrayList storVal = permution1(str);

display(storVal,str);

	
}
public static ArrayList<String> permution1(String str){
if(str.length()==0)
{
    ArrayList<String> retval = new ArrayList<String>();
    retval.add("");
    return retval;
}
char cc = str.charAt(0);
String substr = str.substring(1);
ArrayList<String> myRes = new ArrayList<String>();
ArrayList<String> retRes = permution1(substr);
for(String s:retRes){
    for(int i=0;i<=s.length();i++){
      myRes.add( s.substring(0,i)+cc+s.substring(i));
    
    }
}
return myRes;

}
public static void display(ArrayList storVal,String str){
//String max = str;
int len = storVal.size();
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
if(storVal.get(j).compareTo(storVal.get(i))>0 ){
String temp = storVal.get(j);
storVal.set(j,storVal.get(i));
storVal.set(i,temp);

     }
 }
     
}

int counter = 0;
for(String s : storVal){

    if(s.equals(str)){
       counter = counter+1;
 
    }
    else if(counter == 1){
      
         System.out.println(s);
    }
    
}

}
}

Hi @uttamjaish
Please share your code using coding blocks ide . It would be easier for me to then debug your code and help you further.

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.