Description

Given an array of integers representing asteroids where |value| is size and sign is direction (positive=right, negative=left), return the state after all collisions.

Examples

Input:asteroids = [5,10,-5]
Output:[5,10]
Explanation:

-5 collides with 10, 10 wins.

Input:asteroids = [8,-8]
Output:[]
Explanation:

8 and -8 have equal size but opposite directions. They collide and both are destroyed.

Input:asteroids = [10,2,-5]
Output:[10]
Explanation:

-5 (moving left) collides with 2 (moving right). Since |-5|>2, -5 survives. Then -5 collides with 10, and 10>|-5|, so 10 survives alone.

Constraints

  • 2 ≤ asteroids.length ≤ 10⁴
  • -1000 ≤ asteroids[i] ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!