Problem Submissions Solution

Asteroid Collision

Difficulty: Medium

Acceptance: %

Points: 30.00

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:

  • The smaller asteroid is destroyed.
  • If both are the same size, they both explode.
  • Asteroids moving in the same direction will never collide.

Your task is to determine the final state of the asteroids after all collisions.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(N)

Expected Auxiliary Space: O(N)

Constraints:
  • 1 <= N <= 10^5
  • -1000 <= asteroids[i] <= 1000
  • asteroids[i] != 0
Companies:
Amazon Microsoft Apple Visa
Topics:
Stack
Locked Content
Access Restricted: Please Login to access the code editor and test cases.