Simulate collisions between moving asteroids and return the survivors in order.
You are given an array of integers representing asteroids in a straight line. The absolute value of each integer is the asteroid's size, and the sign indicates its direction:
> 0 means the asteroid is moving to the right< 0 means the asteroid is moving to the leftAll asteroids move at the same speed. When two asteroids moving in opposite directions meet, they collide:
Determine the state of the asteroids after all possible collisions have occurred.
asteroidsabs(asteroids[i]) is the size and the sign is the directionReturn an array containing the asteroids that remain after all collisions, in their original relative order.
1 <= asteroids.length <= $10^{5}$-1000 <= asteroids[i] <= 1000asteroids[i] != 0Example 1
Input
asteroids = [5,10,-5]
Output
[5,10]
Explanation
-5 collides with 10 and is destroyed. 5 and 10 continue moving right.
Example 2
Input
asteroids = [8,-8]
Output
[]
Explanation
The two asteroids are the same size, so both are destroyed.
Example 3
Input
asteroids = [10,2,-5]
Output
[10]
Explanation
2 is destroyed by -5, then -5 is destroyed by 10.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.