A shop's checkout page offers a deal: pick exactly two different items from prices and pay their total. The shopper has budget to spend.
Write bestPair(prices, budget) that returns the largest total of two different items (two different indexes) that is at most budget. If no pair fits, return -1.
Input: prices = [30,45,10,25], budget = 60 Output: 55
45 + 10 and 30 + 25 both make 55, the largest total that is at most 60.
Input: prices = [50,60], budget = 100 Output: -1
The only pair costs 110, which is over budget.
0 <= prices.length <= 10001 <= prices[i] <= 10^61 <= budget <= 2 * 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #6 Best Coupon Pair Under Budget. 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.