GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesAsteroid Belt

Gamified challenge · Stacks

Asteroid Belt

asteroids[i] is the asteroid at position i on the belt, listed left to right. Its absolute value is its size and its sign is its direction: positive drifts right, negative drifts left. All of them move at the same speed, so two asteroids only meet when a right-mover is somewhere to the left of a left-mover.

When two asteroids meet, the smaller one shatters; if they are the same size, both shatter. Asteroids moving the same way never meet. Write survivors(asteroids) that returns the asteroids still flying after every crash, in their left-to-right order, with their original signs.

For [5, 10, -5], -5 hits 10 and shatters, so the answer is [5, 10]. For [10, 2, -5], -5 breaks 2 and then breaks against 10: the answer is [10]. Sizes are never 0.

Sign in to play Asteroid Belt

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account