Tap here to switch tabs
Problem
Submissions

Problem: Asteroid Collision

Asteroid Collision gives an array of signed asteroids, where each sign shows direction and each magnitude shows size. Return the final survivors after collisions, destroying the smaller one or both when sizes match.

Statement

We are provided an array of integers, asteroids, representing asteroids in a row. The absolute integer value of each asteroid represents its size, and the sign represents its direction. A positive sign signifies that the asteroid is moving toward the right direction, while a negative sign indicates it is moving toward the left. All asteroids move at the same speed.

We need to determine the final state of the asteroids after all the collisions have occurred. When two asteroids of different sizes collide, the smaller one will be destroyed. If both asteroids are of the same size, both will be destroyed.

Note: Asteroids moving in the same direction will never collide.

Constraints:

  • 2≤2 \leq asteroids.length ≤103\leq 10^3

  • −103≤-10^3 \leq asteroids[i] ≤103\leq 10^3

  • asteroids[i] ≠0\neq 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Asteroid Collision

Asteroid Collision gives an array of signed asteroids, where each sign shows direction and each magnitude shows size. Return the final survivors after collisions, destroying the smaller one or both when sizes match.

Statement

We are provided an array of integers, asteroids, representing asteroids in a row. The absolute integer value of each asteroid represents its size, and the sign represents its direction. A positive sign signifies that the asteroid is moving toward the right direction, while a negative sign indicates it is moving toward the left. All asteroids move at the same speed.

We need to determine the final state of the asteroids after all the collisions have occurred. When two asteroids of different sizes collide, the smaller one will be destroyed. If both asteroids are of the same size, both will be destroyed.

Note: Asteroids moving in the same direction will never collide.

Constraints:

  • 2≤2 \leq asteroids.length ≤103\leq 10^3

  • −103≤-10^3 \leq asteroids[i] ≤103\leq 10^3

  • asteroids[i] ≠0\neq 0