We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Python 3:
Used a key/value pair to map out each value and increment the times the id has been seen like some sort of counter.
defmigratoryBirds(arr):integer_dictionary={}fornumberinarr:## To prevent an issue where the key doesn't exist in our dictionary## before an addtion assignment "+=" we check whether or not to initialize it.ifnumberininteger_dictionary:integer_dictionary[number]+=1else:integer_dictionary[number]=1## Now we find the upmost maximum value.maximum_value=max(integer_dictionary.values())## And we use that to find our smallest id if there are multiple## high level values.keys_with_maximum_values=[]forkey,valueininteger_dictionary.items():ifvalue==maximum_value:keys_with_maximum_values.append(key)## Returning the smallest id found.returnmin(keys_with_maximum_values)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
Python 3: Used a key/value pair to map out each value and increment the times the id has been seen like some sort of counter.