runguard: warning: timelimit exceeded (wall time): aborting command
runguard: warning: command terminated with signal 15
What is wrong in mycode.
runguard: warning: timelimit exceeded (wall time): aborting command
runguard: warning: command terminated with signal 15
What is wrong in mycode.
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int size=scn.nextInt();
String[] str=new String[size];
for(int i=0;i<str.length-1;i++){
str[i]=scn.next();
}
sort(str);
}
public static void sort(String[] arr){
for(int i=0;i<arr.length-1;i++){
for(int j=0;j<arr.length-1-i;j++){
if(CompareTo(arr[j],arr[j+1])>0){
String temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
public static int CompareTo(String s1,String s2){
int i=0;
while(i<s1.length() && i<s2.length()){
if(s1.charAt(i)>s2.charAt(i)){
return 1;
}
if(s1.charAt(i)<s2.charAt(i)){
return -1;
}
}
if(s1.length()>s2.length()){
return -1;
}else{
return -1;
}
}
link to code
@ubaidshaikh9999,
https://ide.codingblocks.com/s/250631 corrected code.
Sorry for the late reply buddy. Your logic was mostly correct. Just a few small errors here and there.
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.