Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Last Stone Weight

You have stones with given weights. Each turn, take the two heaviest stones with weights x <= y and smash them: if x == y both are destroyed, otherwise the stone of weight y - x remains. Print the weight of the last remaining stone, or 0 if none.

Constraints

1 <= n <= 30 1 <= weight <= 1000

Discussion

No discussions yet.

Rewards · v2.1

Join Shalyam Newsletter

Get exclusive insights with every issue: education, research and innovation news.

One email a week. Unsubscribe any time.