Skip to main content

Last Stone Weight

Simulate stone smashing game Return weight of last remaining stone (or 0 if none) Example: [2,7,4,1,8,1] => 1

Last Stone Weight tests whether you can keep a best-so-far structure honest as you go. It's a great warm-up that builds priority-based reasoning without a ton of moving parts. If your heap represents best candidates right now, the rest falls into place.

Examples

You write

last_stone_weight(stones: List[int])

  1. Example 1

    Input
    stones = [2,7,4,1,8,1]
    returns
    1
  2. Example 2

    Input
    stones = [1]
    returns
    1

The pattern behind it

Arrays & Hashing

I reach for it when

  • You catch yourself scanning the array again for every element.
  • The problem asks about duplicates, pairs, counts or groups.

Say this before you type. Say what the key is and what the value remembers, before you write the loop.

All 127 Arrays & Hashing problems

Heaps

I reach for it when

  • You need the k largest or k smallest items.
  • You repeatedly take the best remaining item.

Say this before you type. Say what the heap holds, how big it stays, and what sits on top.

All 22 Heaps problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Last Stone Weighteasy