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

Last Stone Weight II

Stones have the given weights. In each move two stones of weights x <= y are smashed together: if x == y both are destroyed, otherwise a stone of weight y - x remains. Print the smallest possible weight of the final stone (0 if none remains).

Constraints

1 <= n <= 30 1 <= weight <= 100

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.