Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Asteroid Collision

Medium

Topics
ArrayStackSimulation

Given nums of asteroids (absolute value = size, sign = direction: positive right, negative left), return the state after all collisions. Two moving toward each other: the smaller explodes; equal sizes both explode. Same direction never collide.

Example 1

Input:  asteroids = [5,10,-5]
Output: [5,10]

Example 2

Input:  asteroids = [8,-8]
Output: []

Example 3

Input:  asteroids = [10,2,-5]
Output: [10]

Constraints

  • 2 <= nums.length <= 10^4
  • -1000 <= nums[i] <= 1000
  • nums[i] != 0
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access