You are viewing a single comment's thread. Return to all comments →
javascript
function whatFlavors(cost, money) { let menu = new Map() for (let i = 0; i < cost.length; i++) { if (menu.has(cost[i])) menu.get(cost[i]).push(i + 1) else menu.set(cost[i], [i + 1]) } for (let i = 0; i < cost.length; i++) { if (menu.has(money - cost[i]) && ( cost[i] != money - cost[i] || menu.get(cost[i]).length > 1)) { console.log(menu.get(cost[i]).shift(), menu.get(money - cost[i]).shift()) return } } }
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