A gift shop page lets a buyer pick any set of items from prices, each item at most once, including no items at all (total 0).
Write closestBundleTotal(prices, target) that returns the total of the set whose total is closest to target. If two totals are equally close, return the smaller total.
Input: prices = [4,9,6], target = 12 Output: 13
The possible totals are 0, 4, 6, 9, 10, 13, 15, 19. 13 is 1 away from 12, closer than 10, which is 2 away.
Input: prices = [5,5], target = 7 Output: 5
Totals 0, 5, and 10. 5 is 2 away and 10 is 3 away.
1 <= prices.length <= 151 <= prices[i] <= 10000 <= target <= 15000Run 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 #296 Closest Bundle Price. 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.