Skip to main content
medium

Asteroid Collision

Find state of asteroids after all collisions Positive = moving right, Negative = moving left When asteroids collide: smaller explodes, equal = both explode Asteroids moving same direction never meet Example: [5,10,-5] => [5,10] (10 destroys -5)

This is a stack/invariant problem: once your stack represents the right thing, the rest is routine. Interviewers love it because it reveals your stack invariants and your edge-case discipline. The classic mistake is not being clear about what your stack represents at each step.

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, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.

1Asteroid Collisionmedium
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.

Based onLeetCode

Get a note when something new lands

New company guides, new problems and big changes to Coco. Rare, and you can leave any time. By joining you agree to get these emails.