prices. You have budget coins. You want to buy exactly two snacks (two different positions in the array) without going below zero.
Among all such purchases, pick the one that leaves you with the most money and return what is left. If you cannot afford any two snacks, buy nothing and return budget.prices=[7, 3, 5, 4], budget=10 → 3
The cheapest pair costs 3 + 4 = 7, leaving 3.
prices=[6, 8, 9], budget=12 → 12
Even the cheapest pair costs 14, which is over budget, so you keep all 12.
prices=[5, 5], budget=10 → 0
prices=[7, 3, 5, 4], budget=10
3
Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.