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 challengesSliding Tile 8-Puzzle

Gamified challenge · BFS over states

Sliding Tile 8-Puzzle

A 3 × 3 tray holds tiles 1-8 and one gap, written 0. board[r][c] is the tile on row r, column c. A move slides a tile next to the gap into it, which is the same as moving the gap one step U, D, L or R (it can't leave the tray). The tray is sorted when it reads [[1,2,3],[4,5,6],[7,8,0]].

Write solve(board) that returns the gap's moves as a string, using the fewest moves possible (any shortest answer passes; return "" if it's already sorted). Half of all trays can never be sorted: for those, return "impossible".

Example: [[1,2,3],[4,0,6],[7,5,8]] → "DR": the gap moves down (tile 5 slides up), then right (tile 8 slides left).

Sign in to play Sliding Tile 8-Puzzle

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