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.
An example is easier to explain, for example you have cost array: [2, 1, 3, 5, 6] and money 5:
loop through the array when it handle first element 2, calculate what is left if spend that cost, here is 3, so put 3 and ID of element 2 as a pair into hashmap, next time when you handle 3 in the array, you found it in the hashmap, which value is the other ice cream's ID
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
An example is easier to explain, for example you have cost array: [2, 1, 3, 5, 6] and money 5:
loop through the array when it handle first element 2, calculate what is left if spend that cost, here is 3, so put 3 and ID of element 2 as a pair into hashmap, next time when you handle 3 in the array, you found it in the hashmap, which value is the other ice cream's ID