Notsure what is wrong regarding the code failed for 1 testcase
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan =new Scanner(System.in);
int n=scan.nextInt();
String[]array=new String[n];
for(int i=0;i<array.length&&i<=1000;i++)
{
array[i]=scan.next();
}
int v=0;
int w=0;
String[] arr= sortstrings(v,w,array);
for(String val:arr)
{
System.out.println(val);
}
}
public static String[] sortstrings(int i,int j,String[] array)
{
for(i=0;i<array.length-1;i++)
{
for(j=i+1;j<array.length;j++)
{
if(array[i].charAt(0)>array[j].charAt(0))
{
String temp=array[i];
array[i]=array[j];
array[j]=temp;
}
else if(array[i].charAt(0)== array[j].charAt(0))
{
if(array[i].length()<array[j].length())
{
String temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
}
return array;
}
}