Hello **Programmers/Coders,** Today we are going to share ** solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java**. At Each Problem with Successful submission with

**all Test Cases Passed,**you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for **Migratory Birds** **in Java-HackerRank Problem**. We are providing the **correct and tested solutions** of coding problems present on **HackerRank**. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

**Introduction To Algorithm**

The word **Algorithm** means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.

**Advantages of Algorithms:**

- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.

** Link for the Problem** – Migratory Birds – Hacker Rank Solution

Migratory Birds– Hacker Rank Solution

**Problem:**

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**

**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**

**Sample Input 0**

6 1 4 4 4 5 3

**Sample Output 0**

4

**Explanation 0**

The different types of birds occur in the following frequencies:

- Type : bird
- Type : birds
- Type : bird
- Type : birds
- Type : bird

The type number that occurs at the highest frequency is type , so we print as our answer.

**Sample Input 1**

11 1 2 3 4 5 4 3 2 1 3 4

**Sample Output 1**

3

**Explanation 1**

The different types of birds occur in the following frequencies:

Migratory Birds – Hacker Rank Solution

import java.util.Scanner; /** * @author Techno-RJ * */ public class MigratoryBirds { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; int maxFreqValue = 0, freqId = 0; for (int types_i = 0; types_i < n; types_i++) { int index = in.nextInt(); types[index - 1]++; } for (int i = 0; i < n; i++) { if (types[i] > maxFreqValue) { maxFreqValue = types[i]; freqId = i + 1; } } System.out.println(freqId); in.close(); } }