Back to course home
0% completed
Solution: Asteroid Collision
Problem Statement
You are given an integer array asteroids
of size n, where asteroids[i]
represents the size
and direction
of the i<sup>th</sup> asteroid.
The size
of an asteroid is represented by the absolute value
of asteroids[i]
, and its direction is indicated by the integer's sign: positive for rightward
and negative for leftward
. Each asteroid moves at the same speed
.
When two asteroids collide
, the smaller one shatters
. If they are of equal size
, both are destroyed
. Asteroids moving in the same direction
never collide
.
Return the `final state
.....
.....
.....
Like the course? Get enrolled and start learning!