Ezvor

1167. Minimum Cost to Connect Sticks

MediumArray Preparing judge… LeetCode
ArrayGreedyHeap (Priority Queue)

Hints

Hint 1
How many times does every stick contribute to the answer?
Hint 2
Some of the sticks will be used more than the others. Which sticks should be used the most/least?
Hint 3
The sticks with long lengths cost a lot so we should use these the least.
Hint 4
What if we keep merging the two shortest sticks?