You are given an array of integers, asteroids, where each element represents an asteroid. The absolute value of an element indicates the size of the asteroid, while the sign indicates its direction: positive means moving to the right, and negative means moving to the left. All asteroids move at the same speed.
When two asteroids collide:
Your task is to determine the final state of the asteroids after all collisions.
Example 1
Input: N = 4, asteroids[] = {10, 2, -5, -10}
Output:
Explanation: Asteroid 2 and -5 collide, and -5 destroys 2. Then 10 and -5 collide, and 10 destroys -5. Finally, 10 and -10 collide, and both explode since they are the same size.
Example 2
Input: N = 5, asteroids[] = {4, -4, 2, -2, 8}
Output: {8}
Explanation: 4 and -4 collide and both explode. 2 and -2 collide and both explode. Only 8 remains, as it moves to the right and has no collisions
Sign in to write, run, and submit your solution against the full test suite.