Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f9a08c6

Browse files
Add files via upload
1 parent ce7eecd commit f9a08c6

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

‎Migratory Birds.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the migratoryBirds function below.
10+
def migratoryBirds(arr):
11+
arr.sort()
12+
higher = 0
13+
for i in arr:
14+
if arr.count(i) > higher:
15+
higher = i
16+
return higher
17+
18+
if __name__ == '__main__':
19+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
20+
21+
arr_count = int(input().strip())
22+
23+
arr = list(map(int, input().rstrip().split()))
24+
25+
result = migratoryBirds(arr)
26+
27+
fptr.write(str(result) + '\n')
28+
29+
fptr.close()
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
# You have been asked to help study the population of birds migrating across the continent. Each type of bird you are interested in will be identified by an integer value. Each time a particular kind of bird is spotted, its id number will be added to your array of sightings. You would like to be able to find out which type of bird is most common given a list of sightings. Your task is to print the type number of that bird and if two or more types of birds are equally common, choose the type with the smallest ID number.
57+
58+
# For example, assume your bird sightings are of types . There are two each of types and , and one sighting of type . Pick the lower of the two types seen twice: type .
59+
60+
# Function Description
61+
62+
# Complete the migratoryBirds function in the editor below. It should return the lowest type number of the most frequently sighted bird.
63+
64+
# migratoryBirds has the following parameter(s):
65+
66+
# arr: an array of integers representing types of birds sighted
67+
# Input Format
68+
69+
# The first line contains an integer denoting , the number of birds sighted and reported in the array .
70+
# The second line describes as space-separated integers representing the type numbers of each bird sighted.
71+
72+
# Constraints
73+
74+
# It is guaranteed that each type is , , , , or .
75+
# Output Format
76+
77+
# Print the type number of the most common bird; if two or more types of birds are equally common, choose the type with the smallest ID number.
78+
79+
# Sample Input 0
80+
81+
# 6
82+
# 1 4 4 4 5 3
83+
# Sample Output 0
84+
85+
# 4
86+
# Explanation 0
87+
88+
# The different types of birds occur in the following frequencies:
89+
90+
# Type : bird
91+
# Type : birds
92+
# Type : bird
93+
# Type : birds
94+
# Type : bird
95+
# The type number that occurs at the highest frequency is type , so we print as our answer.
96+
97+
# Sample Input 1
98+
99+
# 11
100+
# 1 2 3 4 5 4 3 2 1 3 4
101+
# Sample Output 1
102+
103+
# 3
104+
# Explanation 1
105+
106+
# The different types of birds occur in the following frequencies:
107+
108+
# Type :
109+
# Type :
110+
# Type :
111+
# Type :
112+
# Type :
113+
# Two types have a frequency of , and the lower of those is type .

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /