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 challengesTwo-Stack Ticket Queue

Gamified challenge · Stacks

Two-Stack Ticket Queue

A box office must serve fans first come, first served, but its only storage is two stacks (you may only push onto or pop from the top of each). You get the day's operations in order: "join X" puts a fan with ticket number X at the back of the line, "serve" serves the fan at the front and hands out their ticket number, and "peek" reports the front fan's ticket number without serving them.

Write runOps(ops) (Python: run_ops(ops)) that returns a list with one number for every `serve` and `peek`, in order: the ticket number, or -1 if the line is empty at that moment. join adds nothing to the output. Solve it with two stacks (an inbox and an outbox); a built-in queue gives the same output but misses the point.

For ["join 5", "join 7", "serve", "join 9", "peek", "serve", "serve"] the answer is [5, 7, 7, 9].

Sign in to play Two-Stack Ticket Queue

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