• + 0 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.

    def migratoryBirds(arr):
        integer_dictionary = {}
        for number in arr:
            ## 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.
            if number in integer_dictionary:
                integer_dictionary[number] += 1
            else:
                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 = []
        for key, value in integer_dictionary.items():
            if value == maximum_value:
                keys_with_maximum_values.append(key)
        
        ## Returning the smallest id found.
        return min(keys_with_maximum_values)