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.
Here is how I solved it using C++. Feel free to leave feedback on my solution:
`cpp
int migratoryBirds(vector arr) {
// Dump each bird type in a hashmap with its frequency
std::unordered_map<int, int> map;
for(int a : arr) {
++map[a];
}
// Then, check each type (start from type 5)
// Return type with highest frequency (starting from end will result in highestCt having lowest ID)
int resultType = 0;
int highestCt = -1;
for(int i = 5; i > 0; --i) {
int count = map[i];
if(count >= highestCt) {
highestCt = count;
resultType = i;
}
}
return resultType;
}`
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 how I solved it using C++. Feel free to leave feedback on my solution:
`cpp
int migratoryBirds(vector arr) {
}`