Asteroid Collision
medium
1. You are given an array asteroids of integers representing asteroids in a row. 2. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). 3. Each asteroid moves at the same speed. 4. You need to find out the state of the asteroids after all collisions. 5. 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 will never meet.
Constraints
1. 2 <= asteroids.length <= 10^4 2. -1000 <= asteroids[i] <= 1000 3. asteroids[i] != 0
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
7
3
2
-1
3
-3
3
-4
Sample Output
1
-4
Question Video