Question: Question 3 ) We are given an array of integers stones where stones [ i ] is the weight of the i - th stone.

Question 3) We are given an array of integers stones where stones[i] is the weight of the
i-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 x and y with xy. The result of this smash
is:
If (x==y), both stones are destroyed, and
If (y is greater than x), the stone of weight x is destroyed, and the stone of weight y has a new
weight y-x.
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 0. What is the time complexity of your program? Explain
your answer. what is the time complexity of your program?
(10 points)
 Question 3) We are given an array of integers stones where

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!