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 challengesTrain Shunting

Gamified challenge · Stack

Train Shunting

Wagons numbered 1 to n arrive on the incoming track in the order given by wagons. Between the tracks is a dead-end siding: P pushes the next incoming wagon into it, and O pops the siding's top wagon onto the outgoing track. The outgoing track must receive 1, 2, …, n in order.

Write shunt(wagons) that returns the moves as a string of P and O, or "IMPOSSIBLE" when it can't be done. For [3, 1, 2] that's "PPOPOO"; for [2, 3, 1] it's "IMPOSSIBLE".

Sign in to play Train Shunting

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