• + 0 comments

    Here is my simple C++ solution,

    int migratoryBirds(vector arr) {

    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;   
    

    }