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.
int cnt = 0;
int prevCnt = 0;
int res = 0;
for( int i =1; i <=5; i++) // if you read the constraint it says only 1 - 5 types guranteed, so we find the max of each element and the corresponding min
{
cnt = std::count (arr.begin(), arr.end(), i);
if( prevCnt < cnt )
{
prevCnt = cnt;
res = i;
}
else if( prevCnt == cnt )
{
res = min(res, i); // here we get the min of the max cnt if they are the same
}
}
return res;
}
Cookie support is required to access HackerRank
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 →
Here is my simple C++ solution,
int migratoryBirds(vector arr) {
}