Question: Question 3 ) We are given an array of integers stones where stones [ i ] is the weight of the i - th stone.
Question We are given an array of integers stones where stonesi is the weight of the
th stone. We are playing a game with the stones. On each turn, we choose the heaviest two
stones and smash them together.
Suppose the heaviest two stones have weights and with The result of this smash
is:
If both stones are destroyed, and
If is greater than the stone of weight is destroyed, and the stone of weight has a new
weight
At the end of the game, there is at most one stone left.
Write an algorithm using a priority queue to return the weight of the last remaining stone.
If there are no stones left, return What is the time complexity of your program? Explain
your answer. what is the time complexity of your program?
points
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
