Hash Tables: Ice Cream Parlor

  • + 0 comments
    from collections import defaultdict
    def whatFlavors(cost, money):
        # Write your code here
        cache = defaultdict(list)
        for idx, c in enumerate(cost, 1):
            if l := cache[money-c]:
                print(l[0], idx)
                return
            cache[c].append(idx)