You are viewing a single comment's thread. Return to all comments →
Javascript solution using Map:
function whatFlavors(cost, money) { const map = new Map(); for (let i = 0; i < cost.length; i++) { var target = money - cost[i]; if (map.has(target)) { console.log(map.get(target), i + 1); break; } map.set(cost[i], i + 1); } }
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 →
Javascript solution using Map: