HackerRank Solution: Migratory Birds

Sakshi Singh
1 min readApr 11, 2019

(IN PYTHON3)

Using List

# Complete the migratoryBirds function below.

def migratoryBirds(arr):

l= [0]*6 #Birds are atmost 5 types(1–5)

for i in arr:

l[i] += 1

k = max(l)

return(l.index(k))

Using Dictionary

# Complete the migratoryBirds function below.

def migratoryBirds(arr):

l = list(arr)

dic = {i:0 for i in l}

for i in l:

dic[i] += 1

for key, value in sorted(dic.items(), key = itemgetter(1), reverse = True):

return key

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sakshi Singh
Sakshi Singh

Responses (1)

Write a response

This is such an elegant solution, i couldn't come up with something by myself. Thank you so much for this. Really. Didn't think of it in this way at all.

--