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.
deffind_matched_flavors(m,a):print"TOTAL MONEY is: {0}".format(m)cost_map={}fori,costinenumerate(a):print"(i, cost) is ({0},{1})".format(i,cost)sunny=costjohnny=m-costprint"prior cost_map {0}".format(cost_map)print"johnny, sunny {0}, {1}".format(johnny,sunny)ifjohnnyincost_map.keys():print"FOUND MATCHED FLAVORS IN ORDER OFFSET +1:"printcost_map[johnny]+1,i+1# BUGFIXED: following else blocks add of NEW cost:flavorIdx if complement already found pre-loaded# else:# BUG-UNFIXED: following with OVERWRITE-LOSE prior flavor with cost duplicating CURRENT flavor cost!# eg. (5, 0) gets overwritten with (5, 1)# i.e. complement must be found on FIRST cost map entry; otherwise we lose all history of# that entry when a duplicate cost entry is added!cost_map[cost]=iprint"updated cost_map {0}".format(cost_map)# MY TEST SCRIPT m=8flavorsToCost=[5,5,3,4,4]find_matched_flavors(m,flavorsToCost)
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 →