Loading problem…
You're building a product recommendation feature for an e-commerce app. Users have a budget, and you need to find two products whose prices sum exactly to their budget (for gift suggestions or bundle recommendations).
Given an array of product prices nums and a target budget target, return the indices of the two products whose prices add up to the target budget.
You may assume that each input has exactly one solution, and you may not use the same product twice.
twoSum([2, 7, 11, 15], 9); // [0, 1] - products at index 0 and 1 sum to 9
twoSum([3, 2, 4], 6); // [1, 2] - products at index 1 and 2 sum to 6
twoSum([3, 3], 6); // [0, 1] - two products with same priceThis problem models real e-commerce features: