A stock video site buys clips by length. prices[k - 1] is what it pays for one clip that is exactly k seconds long, for k from 1 to prices.length. You have a timeline length seconds long and can cut it into whole-second clips of any allowed lengths, using each length as often as you like.
Write bestClipSale(prices, length) that returns the most money you can get for the whole timeline.
Input: prices = [2,5,7,8], length = 4 Output: 10
Two 2-second clips: 5 + 5. One 4-second clip pays only 8.
Input: prices = [3], length = 5 Output: 15
Only 1-second clips are allowed: 5 × 3.
1 <= prices.length <= 1001 <= length <= 10000 <= prices[i] <= 10000Run 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 #520 Sell Timeline Clips for the Most. 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.