You are viewing a single comment's thread. Return to all comments →
My code is not giving ans in time as it is saying "time limit exceeded".What chnages should i do??
import java.util.*; public class tower_breakers { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t,n,i,j,c=0,k,d=0,l;
System.out.println("enter the test cases"); t=in.nextInt(); for(i=0;i<t;i++) { c=0; System.out.println("Enter the size of tower"); n=in.nextInt(); System.out.println("enter the heights"); int a[]=new int[n]; for(k=0;k<n;k++) a[k]=in.nextInt(); for(j=0;j<n;) {d=0; if(a[j]==1) { j++; continue; } else { for(l=(a[j]-1);l>=2;l--) { if(a[j]%l==0) { a[j]=l; c++; d++; break; } } if(d==0) { a[j]=1; c++; j++; } } } if(c%2==0) System.out.println("2"); else System.out.println("1"); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Tower Breakers, Revisited!
You are viewing a single comment's thread. Return to all comments →
My code is not giving ans in time as it is saying "time limit exceeded".What chnages should i do??
import java.util.*; public class tower_breakers { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t,n,i,j,c=0,k,d=0,l;
}