Solution: Last Stone Weight
Let's solve the Last Stone Weight problem using the Heaps pattern.
We'll cover the following...
We'll cover the following...
Statement
You are given an array stones where each element represents the weight of a stone. Repeatedly perform the following operation while there are at least two stones remaining:
Select the two stones with the largest weights, say x and y with x <= y. Smash them together:
If x == y, both stones are destroyed.
If x != y, the stone of weight x is destroyed and the stone of weight y becomes a new stone with weight y - x.
Return the weight of the final remaining stone. If no stones remain, return
Constraints: