Practice Asteroid Collision
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
We are given an array asteroids of integers representing asteroids in a row. The indices of the asteriod in the array represent their relative position in space. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet.
Source: Asteroid Collision on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
asteroids = [5,10,-5]
[5,10]
# Example 2
asteroids = [8,-8]
[]
# Example 3
asteroids = [10,2,-5]
[10]
Constraints
Related LeetCode Problems
Practice more problems similar to Asteroid Collision.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.