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 challengesKnight's Tour

Gamified challenge · Backtracking

Knight's Tour

A knight stands on square (startRow, startCol) of an n × n board (rows and columns 0 to n - 1). Each jump moves it 2 squares one way and 1 square the other (an L). It must land on every square exactly once; it doesn't need to return to the start.

Write tour(n, startRow, startCol) that returns the board as n rows of n numbers, where board[r][c] is the move number on which the knight lands on (r, c): 0 for the start square, then 1, 2, … up to n² - 1. Any valid tour passes. If no tour exists (for example on a 3 × 3 or 4 × 4 board), return an empty list [].

Boards go up to 8 × 8, where blind backtracking is far too slow: choose the next square cleverly.

Sign in to play Knight's Tour

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