Ice Cream Parlor

  • + 4 comments

    @kb24 @vsaxena115 - Or you could achieve O(n) running time by storing the ice cream flavor prices in a hash table. So then you would just iterate through each of the prices, subtract the price from the money M that you have to spend, and then look up the difference in your hash table to see if there exists a flavor for that price. This would yield a runtime of O(n) + O(n) * O(1) = O(n).