Ice Cream Parlor

  • + 2 comments

    You can't use just a 'standard' hashtable that simply stores the prices, since you generally cannot figure out the corresponding index that you need to output. You would either need a hashmap to store the index along with the price, or you may use an array of length M instead of the hashmap: when scanning C(i), you store the index number i into the (M-C(i))'th element of the array. That way you can always directly figure out the index from a given price later during the scan.