Before the first paint, a page may preload some of its assets. Asset i takes sizes[i] kilobytes and has a usefulness score values[i]. The total size of preloaded assets must not exceed budget kilobytes, and each asset is preloaded at most once.
Write bestPreload(sizes, values, budget) that returns the largest total usefulness you can preload.
Input: sizes = [1,3,4], values = [15,20,30], budget = 4 Output: 35
Assets 0 and 1 take exactly 4 KB and are worth 15 + 20.
Input: sizes = [5], values = [10], budget = 4 Output: 0
The only asset doesn't fit.
1 <= sizes.length <= 100sizes.length === values.length1 <= sizes[i] <= 10000 <= values[i] <= 10000 <= budget <= 1000Run 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 #510 Preload Assets Within a Byte 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.