• + 0 comments

    Here is my c++ solution you can find the explanation here : https://youtu.be/poQPrHTMe08

    int migratoryBirds(vector<int> arr) {
        map<int, int> mp;
        int cnt = 0, id;
        for(int i = 0; i < arr.size(); i++)mp[arr[i]]++;
        for(auto it = mp.begin(); it != mp.end(); it++){
            if(it->second > cnt || (it->second == cnt && it->first < id)){
                cnt = it->second;
                id = it->first;
            }
        }
        return id;
    }