Recursion-Dictionary Order(Larger)

why it give time limit?
import java.util.*;
public class Main {
public static void main(String args[]) {

  Scanner kb=new Scanner(System.in);
  String s=kb.nextLine();
  ArrayList<String> list=perm(s);
  String []word=new String[list.size()];
  int l=0;
  for(int i=0;i<list.size();i++)
      {
		 String str1=list.get(i);
         if(s.compareTo(str1)<0)
		   {word[l]=str1;
		      l++;
		   }
	  }	 
      
	 for(int i=0;i<l-1;i++)
	    {
		  for(int j=i+1;j<l;j++)
		     {
				 if(word[i].compareTo(word[j])>0)
				      {
						 String temp=word[i];
						 word[i]=word[j];
						 word[j]=temp;
					  }
			 }
		} 
      for(int i=0;i<l;i++)
	     System.out.println(word[i]);
}

public static ArrayList perm(String s)
{
if(s.length()==0)
{
ArrayList list=new ArrayList<>();
list.add("");
return list;
}
char c=s.charAt(0);
String str=s.substring(1);

	 ArrayList<String> list1=perm(str);
	 ArrayList<String> result=new ArrayList<>();
    
	 for(int i=0;i<list1.size();i++)
	     {
           String s2=list1.get(i);

		   for(int j=0;j<=s2.length();j++)
		      {
				  String s3=s2.substring(0,j) +c+ s2.substring(j);
				  result.add(s3);
			  }

		 } 
    return result;
  }

}

@abhishekg,
https://ide.codingblocks.com/s/196521 Corrected code.

Your sorting algo was giving TLE. And comparison operator was giving TLE

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.