Skip to content

#735 - Asteroid Collision

MediumStack
Open on LeetCode

Given an array asteroids of integers, the absolute value represents size and the sign represents direction (positive = moving right, negative = moving left). Asteroids moving the same direction never collide. When two asteroids meet, the smaller one explodes; if both are the same size, both explode. Find the state of the asteroids after all collisions.

InputOutput
asteroids = [5,10,-5][5,10]
asteroids = [8,-8][]
asteroids = [10,2,-5][10]

Released under the MIT License.