Asteroid Collision
Updated
Problem statement
An array describes asteroids in a row. The absolute value of each integer is the asteroid's size, while its sign gives its direction: positive moves right and negative moves left. All asteroids move at the same speed.
When two asteroids meet, the smaller one is destroyed. If they have equal size, both are destroyed. Asteroids moving in the same direction never meet.
Return the surviving asteroids in their original order.
Function
asteroidCollision(asteroids: int[]) → int[]Examples
Example 1
asteroids = [5,10,-5]return = [5,10]The asteroid of size 10 destroys the left-moving asteroid of size 5.
Example 2
asteroids = [8,-8]return = []The two asteroids have equal size, so both disappear.
Example 3
asteroids = [-2,-1,1,2]return = [-2,-1,1,2]No right-moving asteroid appears to the left of a left-moving asteroid, so no collision occurs.
Constraints
1 <= asteroids.length <= 10^5-10^4 <= asteroids[i] <= 10^4asteroids[i] != 0
More Adobe interview questions
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Lowest Common Ancestor Only When Both Targets ExistONSITE INTERVIEW · Seen Aug 2026
- Lowest Common Ancestor with Parent PointersONSITE INTERVIEW · Seen Aug 2026
- Next and Previous Lexicographic PermutationONSITE INTERVIEW · Seen Aug 2026
- Farthest Affordable Shop per QueryONSITE INTERVIEW · Seen Aug 2026
- Minimum Removals for a Nice ArrayONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Trie: Add and Search WordsONSITE INTERVIEW · Seen Jul 2026
- Base Unit ConversionsOA · Seen Nov 2026
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Asteroid CollisionZscaler · ONSITE INTERVIEWZscaler interview questions
- Asteroid CollisionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Exclusive Time of FunctionsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Implement Stack Push and Pop OperationsLSEG · ONSITE INTERVIEWLSEG interview questions