-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigratoryBirds.java
More file actions
47 lines (36 loc) · 940 Bytes
/
Copy pathMigratoryBirds.java
File metadata and controls
47 lines (36 loc) · 940 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
39
40
41
42
43
44
45
46
47
package rank;
import java.util.ArrayList;
import java.util.List;
/**
* created by @author suraj on 15/11/19
*/
public class MigratoryBirds {
static int migratoryBirds(List<Integer> arr) {
int ar[] = new int[5];
for (Integer bird : arr) {
ar[--bird]++;
}
int id = Integer.MAX_VALUE;
int maxCount = -1;
for (int i = 0; i < ar.length; i++) {
if (ar[i] == maxCount && i < id) {
id = i;
} else if (ar[i] > maxCount) {
id = i;
maxCount = ar[i];
}
}
return id + 1;
}
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
//1 4 4 4 5 3
list.add(1);
list.add(4);
list.add(4);
list.add(4);
list.add(5);
list.add(3);
System.out.println(migratoryBirds(list));
}
}