Problem
Minimum Stick Connection Cost
Learn this problemProblem statement
You are given an integer array sticks, where each element is the length of a stick.
You may connect any two sticks with lengths x and y. The new stick has length x + y, and the cost of this operation is also x + y.
Return the minimum total cost required to connect all sticks into one stick.
Function
minimumStickConnectionCost(sticks: int[]) → intExamples
Example 1
sticks = [2, 4, 3]return = 14Connect 2 and 3 for cost 5, then connect 5 and 4 for cost 9. The total cost is 14.
Example 2
sticks = [1, 8, 3, 5]return = 30One optimal sequence is 1 + 3 = 4, then 4 + 5 = 9, then 8 + 9 = 17, for total cost 4 + 9 + 17 = 30.
Constraints
1 <= sticks.length <= 1041 <= sticks[i] <= 104
More Amazon problems
- Find Maximum Total Amount (SDE I, Fungible :)OA · Seen Jul 2026
- Meeting Rooms IIPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · ONSITE INTERVIEW · Seen Jul 2026
- Single Element in a Sorted ArrayPHONE SCREEN · Seen Jul 2026
- Count the Number of Complete ComponentsPHONE SCREEN · Seen Jul 2026
- Cousins in Binary Tree IIONSITE INTERVIEW · Seen Jul 2026
- Minimum Operations to Make an Array ContinuousONSITE INTERVIEW · Seen Jul 2026
- Vertical Order Traversal of a Binary TreeONSITE INTERVIEW · Seen Jul 2026