Solution: Connecting n Pipes with Minimum Cost
This review provides a detailed analysis of the solution to connect n pipes with the minimum cost.
Solution #1: Brute Force
In the brute force method, we try all combinations of pipes possible (line34) in order to find the minimum possible cost.
Time Complexity
The time Complexity is because we find all possible combinations and out of that choose the one where we can find the minimum cost.
Solution #2: Sorting
We optimize the solution by sorting the array and choosing the minimum pipes first.
If you look at the animation present in the previous lesson, you will notice that the lengths of the pipes which are picked first are included iteratively (i.e. each time); therefore, we want them to be as small as possible. Now, let’s be ...