Skip to main content
Medium Stack Medium frequency

Asteroid Collision

Open on LeetCode

Approach Summary

Push positive asteroids onto the stack. For negative ones, pop and compare until stack is empty or top is negative. Simulate collisions.

How to Recognize This Pattern

  • Collisions between opposing elements — last-in-first-out resolution
  • Stack models "pending" asteroids

Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(n)

Tags

Array Stack Simulation

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee