Problem
You get an integer array asteroids that shows asteroids in a row. The absolute value of an item is the size of the asteroid. The sign is its direction: positive moves right, and negative moves left.
All the asteroids move at the same speed. When two asteroids meet, the smaller asteroid explodes. If both have the same size, both explode. Two asteroids that move in the same direction never meet.
Return the asteroids that remain after all the collisions, in their order in the row.
Example 1
- Input:
- asteroids = [4,7,-6]
- Output:
- [4,7]
- Explanation:
- The asteroids 7 and -6 meet. The asteroid -6 explodes because it is smaller.
Example 2
- Input:
- asteroids = [3,-3,2]
- Output:
- [2]
- Explanation:
- The asteroids 3 and -3 have the same size, so both explode. The asteroid 2 moves right and meets nothing.
Example 3
- Input:
- asteroids = [-2,5,1,-9,4]
- Output:
- [-2,-9,4]
- Explanation:
- The asteroid -9 destroys 1 and then 5. The asteroids -2 and -9 both move left, so they never meet.
Constraints
- 2 <= asteroids.length <= 10^4
- -1000 <= asteroids[i] <= 1000
- asteroids[i] != 0
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- 132 Pattern
Coding · Array · Binary Search · Monotonic Stack
- Beautiful Towers II
Coding · Array · Monotonic Stack · Stack
- Binary Searchable Numbers in an Unsorted Array
Coding · Array · Binary Search · Monotonic Stack
- Buildings With an Ocean View
Coding · Array · Monotonic Stack · Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 3 records
Amazon
Leetcode 735. Asteroid Collision
Reported Jul 22, 2025 · 2 source reports
INTERN, MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceJPMorgan Chase
Leetcode 735. Asteroid Collision
Reported Mar 31, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 735. Asteroid Collision
Reported Nov 27, 2024 · 1 source report
JUNIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 5 records
D. E. Shaw
Asteroid Collision
Reported date not specified · Source window: 3mo