You are viewing a single comment's thread. Return to all comments →
instead of using two loops, we can solve it in one loop. static int birthdayCakeCandles(int[] ar) {
int size = ar.length, max = Integer.MIN_VALUE ,count = 0; //find tallest candle and count for (int i=0;i<size; i++) { if (ar[i]>max) { max = ar[i]; count = 1; } else if (ar[i]==max) { count++; } } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
instead of using two loops, we can solve it in one loop. static int birthdayCakeCandles(int[] ar) {