Connect Ropes to Minimise the Cost
Easy

Problem Statement

Given n ropes of different lengths, connect them into a single rope with the minimum possible cost. The cost to connect two ropes is equal to the sum of their lengths.

Examples

1Example 1
Input:
{ "arr": [ 4, 3, 2, 6 ] }
Output:
29
2Example 2
Input:
{ "arr": [ 1, 2, 3, 4, 5 ] }
Output:
33
3Example 3
Input:
{ "arr": [ 4, 2, 7, 6, 9 ] }
Output:
62
Loading...

Sign in to Run Code and Submit