Question: Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more

Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids.

Example

There are two each of types and , and one sighting of type . Pick the lower of the two types seen twice: type .

Function Description

Complete the migratoryBirds function in the editor below.

migratoryBirds has the following parameter(s):

  • int arr[n]: the types of birds sighted

Returns

  • int: the lowest type id of the most frequently sighted birds

Input Format

The first line contains an integer, , the size of . The second line describes as space-separated integers, each a type number of the bird sighted.

Constraints


  • It is guaranteed that each type is , , , , or .

Sample Input 0

61 4 4 4 5 3

Sample Output 0

4























Given an array of bird sightings where every element represents a birdtype id, determine the id of the most frequently sighted type. If

Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids. Example arr = [1,1,2,2,3] There are two each of types 1 and 2, and one sighting of type 3. Pick the lower of the two types seen twice: type 1. Function Description Complete the migratoryBirds function in the editor below. migratory Birds has the following parameter(s): int arr[n]: the types of birds sighted Returns int: the lowest type id of the most frequently sighted birds Input Format The first line contains an integer, n, the size of arr. The second line describes arr as n space-separated integers, each a type number of the bird sighted. Constraints 5 n 2x105 It is guaranteed that each type is 1, 2, 3, 4, or 5. Sample Input 0 6 1 4 4 4 5 3 Sample Output 0

Step by Step Solution

3.42 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilHashMap import javautilMap public class MigratoryBi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!