The problem. You have n ropes with lengths ropes[i]. Joining two ropes of lengths a and b makes one rope of length a + b and costs a + b. Join all the ropes into one, and return the minimum total cost.
ropes = [4, 3, 2, 6] -> 29
ropes = [1, 2, 3] -> 9 (1 + 2 = 3, then 3 + 3 = 6)
ropes = [2, 2, 3, 3] -> 20 (2 + 2 = 4, 3 + 3 = 6, 4 + 6 = 10)
ropes = [5] -> 0 (nothing to join)Free account
Sign up to read the rest of this lesson: 7 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come