You have some number of sticks with positive integer lengths. These lengths are given as an array sticks, where sticks[i] is the length of the iᵗʰ stick.
You can connect any two sticks of lengths x and y into one stick by paying a cost of x + y. You must connect all the sticks until there is only one stick remaining.
Return the minimum cost of connecting all the given sticks into one stick in this way.
Example 1:
Input: sticks = [2,4,3]
Output: 14Explanation:
You start with sticks = [2,4,3].
Example 2:
Input: sticks = [1,8,3,5]
Output: 30Explanation:
You start with sticks = [1,8,3,5].
Example 3:
Input: sticks = [5]
Output: 0Explanation:
There is only one stick, so you don't need to do anything. The total cost is 0.
Constraints:
1 <= sticks.length <= 10⁴1 <= sticks[i] <= 10⁴