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:

Edge case with empty result.

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

Works with negative numbers.

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!