A shopper has a gift card worth exactly total and wants two different items from prices that use it up exactly.
Write giftCardPair(prices, total) that returns the indexes [i, j] of the two items, with i < j. Exactly one pair works for every test.
Input: prices = [25,40,10,60], total = 50 Output: [1,2]
40 + 10 = 50.
Input: prices = [15,35,35], total = 70 Output: [1,2]
Two different items can have the same price.
2 <= prices.length <= 2 * 10^5-10^9 <= prices[i], total <= 10^9total.Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #27 Pair of Gift Cards. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.