-
Notifications
You must be signed in to change notification settings - Fork 0
/
migratory-birds
53 lines (42 loc) · 1.18 KB
/
migratory-birds
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
48
49
50
51
52
53
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'migratoryBirds' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY arr as parameter.
#
def migratoryBirds(arr):
dic = {}
for elem in arr:
if elem not in dic:
dic[elem] = 1
else:
dic[elem] += 1
lista = sorted(dic.items() , reverse=True, key=lambda x: x[1])
end = len(lista)
while end > 1:
change = False
counter = 0
while counter < (end-1):
if lista[counter][1] == lista[counter+1][1] and lista[counter][0] > lista[counter+1][0]:
change = True
temporary = lista[counter]
lista[counter] = lista[counter+1]
lista[counter+1] = temporary
counter += 1
if not change:
break
end -= 1
return(lista[0][0])
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = migratoryBirds(arr)
fptr.write(str(result) + '\n')
fptr.close()