A tiny LED display draws digits with lit pixels. Drawing digit d (1 to 9) uses costs[d - 1] pixels, and the digit 0 can't be drawn. You must light exactly budget pixels, and any digit may be drawn many times.
Write biggestNumber(costs, budget) that returns, as a string, the largest number you can draw using exactly budget pixels. If it can't be done, return "0".
Input: costs = [5,4,3,6,7,8,3,6,6], budget = 10 Output: "772"
At most three digits fit. Two 7s (3 pixels each) and a 2 (4 pixels) use exactly 10, and 772 is the largest order.
Input: costs = [2,2,2,2,2,2,2,2,2], budget = 5 Output: "0"
Every digit costs 2, so an odd budget can't be spent exactly.
costs.length === 91 <= costs[i] <= 50001 <= budget <= 100000Run 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 #522 Biggest Number for a Pixel 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.