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.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1. 2 <= asteroids.length <= 10^4
2. -1000 <= asteroids[i] <= 1000
3. asteroids[i] != 0

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
7
3
2
-1
3
-3
3
-4
Output
1
-4
Previous
Remove K Digits
Next
Remove Duplicate Letters

Related Questions