You are viewing a single comment's thread. Return to all comments →
you can reduce the first for loop using the following statement
for(int i=0 ; i < ar.length ; i++) type[ar[i]-1]++;
rest of your code seems to be efficient but appears to be hard coded. This can be re-written like this
int max = type[0]; int maxInd = 0; for(int i=0 ; i < type.length ; i++){ if(type[i] > max){ max = type[i]; maxInd = i; } } return maxInd+1;
You have specified (type[i] >= max). This may give you wrong result in any of the following test cases. replace ">=" with "=".
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
you can reduce the first for loop using the following statement
rest of your code seems to be efficient but appears to be hard coded. This can be re-written like this
You have specified (type[i] >= max). This may give you wrong result in any of the following test cases. replace ">=" with "=".