A video editor has a timeline from 0 to length seconds and must split it at every position listed in cuts. Each split works on one piece at a time and costs the length of the piece being split. You may make the splits in any order.
Write cheapestSplits(length, cuts) that returns the smallest total cost of making every split.
Input: length = 6, cuts = [1,3] Output: 9
Split at 3 first (piece of 6), then at 1 (piece of 3): 6 + 3. Splitting at 1 first costs 6 + 5.
Input: length = 5, cuts = [3] Output: 5
One split of the whole timeline.
2 <= length <= 10^61 <= cuts.length <= 1000 < cuts[i] < length, all different, in any orderRun 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 #546 Cheapest Way to Split a Timeline. 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.