ropes. They all need to be spliced into a single long rope.
At each step you can splice any two ropes of lengths x and y into one of length x + y, and that splice costs x + y. You keep going until only one rope is left.
Return the minimum total cost of the job.ropes=[6, 2, 2, 3] → 24
2 + 2 = 4 (pay 4), then 3 + 4 = 7 (pay 7), then 6 + 7 = 13 (pay 13). Total 24.
ropes=[9] → 0
There is only one rope, nothing to splice.
ropes=[4, 4, 4] → 20
ropes=[6, 2, 2, 3]
24
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.