forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigratoryBirds.java
More file actions
38 lines (32 loc) · 891 Bytes
/
MigratoryBirds.java
File metadata and controls
38 lines (32 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
import java.io.*;
/**
* Created by rajat goyal on 3/19/2017.
*/
public class MigratoryBirds {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] types = new int[n];
for (int types_i = 0; types_i < n; types_i++) {
types[types_i] = in.nextInt();
}
maximumTypeNum(types, n);
}
public static void maximumTypeNum(int[] types, int n) {
int count[] = new int[5];
for (int i = 0; i < n; i++) {
count[types[i] - 1]++;
}
int max = count[0];
int type = 0;
for (int i = 0; i < 5; i++) {
if (count[i] > max) {
max = count[i];
type = i;
}
}
// convert it again to 1-index
System.out.println(type + 1);
}
}