WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Wall Street Quant · Puzzles & Problems · question 33 of 155

On an 8x8 chessboard, a knight starts at any square and moves in legal chess moves (an L shape). Can the knight tour the entire board, visiting every square exactly once, and return to the original square?

📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

Yes, a knight can make a tour of an 8x8 chessboard, visiting every square exactly once and return to the original square. This is known as a closed Knight’s Tour.

A Knight’s Tour is solved using Warnsdorff’s rule, a heuristic algorithm that orders the possible moves based on the number of next moves the knight will have. The algorithm suggests always moving to an adjacent square with the least number of next legal moves.

Before diving into the mathematical solution, let’s denote the moves of the knight:

A single move of the knight can be described as a combination of 2 moves: one step of 2 squares and another step of 1 square. Given an (x, y) position on the board, the legal knight moves can be expressed as: (x ± 2, y ± 1) or (x ± 1, y ± 2).

Now let’s find the closed Knight’s Tour on an 8x8 chessboard.

1. Initialize an 8x8 grid as the chessboard: 64 total squares.

2. Assign each cell with the number of possible moves based on Warnsdorff’s rule. In an 8x8 grid, a cell can have a minimum of 2 and a maximum of 8 possible moves.

3. Select a starting cell (e.g., the top-left cell).

4. Make a legal move to the adjacent cell with the least number of possible moves, and mark the current cell as visited.

5. Repeat step 4 until all cells are visited. If you reach a dead-end (i.e., no next possible moves), backtrack to the previous cell and try another move.

Here’s a simple example of a closed Knight’s Tour starting at the top-left corner of an 8x8 chessboard (row numbers represent the order of visited cells):

1 50 39 34 3 38 23 36
20 5 2 49 40 35 4 25
51 18 21 10 47 26 37 22
6 19 8 53 46 41 48 33
17 52 45 58 9 54 27 44
12 7 56 43 60 29 42 55
59 14 11 16 61 64 31 28
13 62 57 30 15 32 63 24

However, it’s important to note that there might be multiple closed Knight’s Tours on an 8x8 chessboard, and they can start from various cells.

For a visual representation, you can refer to the following diagram of a closed Knight’s Tour:

[1]--[50]--[39]--[34]--[3]--[38]--[23]--[36]
 |    |    |    |    |    |    |    |    |
[20]--[5]--[2]--[49]--[40]--[35]--[4]--[25]
 |    |    |    |    |    |    |    |    |
[51]--[18]--[21]--[10]--[47]--[26]--[37]--[22]
 |    |    |    |    |    |    |    |    |
[6]--[19]--[8]--[53]--[46]--[41]--[48]--[33]
 |    |    |    |    |    |    |    |    |
[17]--[52]--[45]--[58]--[9]--[54]--[27]--[44]
 |    |    |    |    |    |    |    |    |
[12]--[7]--[56]--[43]--[60]--[29]--[42]--[55]
 |    |    |    |    |    |    |    |    |
[59]--[14]--[11]--[16]--[61]--[64]--[31]--[28]
 |    |    |    |    |    |    |    |    |
[13]--[62]--[57]--[30]--[15]--[32]--[63]--[24]

In this diagram, a knight starts at cell 1 and moves through cells 2, 3, 4, ..., 64 in the order shown, finally returning to the starting cell.

Keep in mind that the algorithm’s efficiency depends on the size of the chessboard, backtracking, and the implementation itself. However, Warnsdorff’s rule provides a solid heuristic for solving the Knight’s Tour problem.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Wall Street Quant interview — then scores it.
📞 Practice Wall Street Quant — free 15 min
📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

All 155 Wall Street Quant questions · All topics