You are viewing a single comment's thread. Return to all comments →
Thank you Joseph, your explanation of the problem brouhgt me to this simple solution that run in O(n):
int ret = 0; int max = 0; for(int a : ar){ if(a > max){ ret = 1; max=a; } else if(a == max) ret++; } return ret;
Sometimes the hardest part of these problems is finding what the question is asking more than how to solve it.
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 →
Thank you Joseph, your explanation of the problem brouhgt me to this simple solution that run in O(n):
Sometimes the hardest part of these problems is finding what the question is asking more than how to solve it.