Ice Cream Parlor

  • + 2 comments

    Python solution, O(n) runtime, no need to sort

    def icecreamParlor(m, arr):
        test = dict()
        for i in range(len(arr)):
            if arr[i] not in test: 
                test[m-arr[i]] = i+1 #dollar match amount is key, 1based index is value
            else:
                return sorted([i+1, test[arr[i]]])