We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.Scanner;// Time Complexity: O(n)publicclassSolution{staticfinalintNUM_TYPES=5;staticintmigratoryBirds(int[]birds){/* Get counts of each type */int[]count=newint[NUM_TYPES+1];for(intnum:birds){count[num]++;}/* Find max */intmaxIndex=1;for(inti=0;i<count.length;i++){if(count[i]>count[maxIndex]){maxIndex=i;}}returnmaxIndex;}publicstaticvoidmain(String[]args){/* Save input */Scannerscan=newScanner(System.in);intn=scan.nextInt();int[]birds=newint[n];for(inti=0;i<n;i++){birds[i]=scan.nextInt();}scan.close();/* Calculate result */intresult=migratoryBirds(birds);System.out.println(result);}}
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.