Challenge: Connecting n Pipes With Minimum Cost
Given n pipes, find the minimum cost of connecting them.
We'll cover the following...
We'll cover the following...
Problem statement
Implement a function that connects n pipes of different lengths, into one pipe. You can assume that the cost to connect two pipes is equal to the sum of their lengths. We need to connect the pipes with minimum cost.
Input
A list containing lengths of n pipes
Output
The total cost of connecting the pipes
Sample input
pipes = [4, 3, 2, 6]
Sample output
result = 29
Coding exercise
First, take a close look at this problem and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided in the solution section. Good luck!