Problem
We are given an arrayasteroids of integers representing asteroids in a row. The indices of the asteroid in the array represent their relative position in space.
For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed.
Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction, or two moving away from each other, will never meet.
Examples
Constraints
- 2 <= asteroids.length <= 10^4
- -1000 <= asteroids[i] <= 1000
asteroids[i] != 0