FreeCareerPath
Build the PrimitiveEasy

Last Stone Weight

Write `last_stone_weight(stones)` simulating this: repeatedly take the two heaviest stones and smash them. Equal weights destroy both; otherwise the difference goes back into the pile. Return the last remaining weight, or `0`. [2,7,4,1,8,1] -> 1 Sorting after every smash is O(n^2 log n). A heap makes each round O(log n). Python only has a min-heap, so negate the values — and remember to negate back when you read them.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Last Stone Weight" are saved to your account — logging in takes a few seconds.

Last Stone Weight — FreeCareerPath