Asteroid Collision Problem
Asteroid Collision Problem — ExecCode Medium DSA Practice
Solve the Asteroid Collision problem on ExecCode. Free online medium DSA practice in Stack. Write and run code in Java, C++, Python — no signup required to run.
Problem description
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive = right, negative = left). Find the state of the asteroids after all collisions.
Examples
Input asteroids = [5, 10, -5, -10, 8, -3]; Output [5, 8]. Input asteroids = [10, 2, -5]; Output [10]
Constraints
2 ≤ asteroids.length ≤ 10⁴ -1000 ≤ asteroids[i] ≤ 1000 asteroids[i] ≠ 0
Practice Asteroid Collision free on ExecCode. Browse DSA problems, topic map, and placement guides.