We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all 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.