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 challengesBall Sort

Gamified challenge · State-space search

Ball Sort

Coloured balls are jumbled across test tubes that each hold capacity balls. tubes[i] lists tube i's balls from bottom to top as colour letters ("rgr" is red, green, red; "" is empty). A move "i j" takes the top ball of tube i onto tube j, allowed only when tube j is empty, or not full with the same colour on top.

Write sortBalls(tubes, capacity) (sort_balls in Python) that returns at most 200 moves after which every tube is empty or full of one colour; any such list passes. For ["ggg", "rr", "r"] with capacity 3, ["2 1"] sorts it in one move.

Sign in to play Ball Sort

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