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.
Your code here looks very clean, and it passes all of the HackerRank test suite for this problem.
However, when I tested a couple cases to understand why Gayle would use BinarySearch for this problem; I found a bug in this Map approach. I believe this test could be helpful to add to the Hacker Rank suite to align with the original Problem as stated by Gayle:
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)
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
Hi @zoomis_gogo!
Your code here looks very clean, and it passes all of the HackerRank test suite for this problem.
However, when I tested a couple cases to understand why Gayle would use BinarySearch for this problem; I found a bug in this Map approach. I believe this test could be helpful to add to the Hacker Rank suite to align with the original Problem as stated by Gayle: