Surviving Asteroids After Collisions

Asked at IMC Trading · Coding Questions · Difficulty: Medium

A row of asteroids drifts along a line, all at the same speed. Each one moves either left or right and has a size. When two neighbours move towards each other they collide: the bigger one destroys the smaller one, and if both have the same size both are destroyed. Asteroids moving in the same direction never meet. Work out which asteroids are left once no more collisions can happen.

Loading the problem…