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

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.