735. Asteroid Collision

Practice Asteroid Collision for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Asteroids sit in a row, all moving at the same speed. The absolute value is the size; a positive value moves right, a negative value moves left.

When two asteroids meet, the smaller one explodes; if they are the same size, both explode. Asteroids moving in the same direction never meet. Return the asteroids left after all collisions, in their original order.

Example

asteroids = [5,10,-5]  ->  [5,10]   (10 and -5 meet, -5 explodes)
asteroids = [8,-8]     ->  []

Constraints