set19

Find two prices that sum to a coupon target

19 / 26
read the snippet · pick its Big-O
function twoSum(prices, target) {
const seen = new Map();
for (let i = 0; i < prices.length; i++) {
const need = target - prices[i];
if (seen.has(need)) return [seen.get(need), i];
seen.set(prices[i], i);
}
return null;
}