Accepted solution

Migratory Birds(Hacker Rank)

Open original problem
Source code

int migratoryBirds(vector<int> arr) {

  sort(arr.begin(),arr.end());

  int count=0,max=0,Number=0;

  for(int i=0; i<arr.size(); i++)

    {

        count=0;

        for(int j=i+1; arr[i]==arr[j]; j++)

        {

            if(arr[i]==arr[j]) ///find total Occurrences

            {

                count++;

            }

        }

        if(count>max)

        {

            max = count;

            Number = arr[i];

        }

    }

    return Number;

}
Join the discussion

Add your comment