Leetcode #1167 Minimum cost to connect sticks

If you notice the problem closely — what you need is a sorted list of the array everytime. What better data structure to use than a heap?

Every time we evaluate the cost of the sticks being considered, we add the cost of the first and the second stick polled into the heap again. This continues until there is only one stick left in the heap to be considered.

Time complexity = O(n), space complexity = O(n)