• + 0 comments

    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;
    

    }`