Code RoomAsteroid collision
MediumPrep Room Coding #775

Asteroid collision

CodingAlgorithms & data structuresMid–Senior~25 min

Given an array of integers representing asteroids in a row, the absolute value is each asteroid's size and the sign is its direction (positive = moving right, negative = moving left). All asteroids move at the same speed. When two asteroids collide, the smaller one explodes; if both are equal, both explode. Two asteroids moving in the same direction, or a left-mover to the left of a right-mover, never meet. Return the state of the asteroids after all collisions resolve.

Implement
asteroid_collision(asteroids: list[int]) → list[int]
Examples
in[[5,10,-5]]out[5,10]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[5,10,-5]][5,10]not run yetsample