691. Asteroid Collision
0
Easy
Given an array of integers called asteroids, each representing an asteroid in a row. The absolute value of each asteroid represents its size, and the sign represents its direction (positive for right, negative for left). All asteroids move at the same speed. Determine the state of the asteroids after all collisions. If two asteroids collide, the smaller one will explode. If two asteroids have the same size, both will explode. Two asteroids moving in the same direction will never collide.
Input Format
The first line of input contains the size N of the array. The second line contains N elements of the array, representing the asteroids.
Output Format
Print the final state of the asteroids after all collisions.
Example
Input
3
5 10 -5
Output
5 10
Constraints
2 <= asteroids.length <= 10000
-1000 <= asteroids[i] <= 1000
asteroids[i] != 0
-1000 <= asteroids[i] <= 1000
asteroids[i] != 0
Loading...
View Submissions
Console