← Microsoft questions

Knight shortest path on a chessboard

Filed under Microsoft · Also reported at MakeMyTrip

Free read 3 of 3

Confirm board size and whether coordinates are 0-indexed or 1-indexed.

The question

Given a standard 8x8 chessboard, find the minimum number of steps a knight needs to reach a destination coordinate from a starting coordinate.

Constraints

  • Board dimensions are fixed at 8x8 (or generalized to N x N).
  • Start and destination coordinates are valid grid locations.

Examples

Input
start = (0, 0), dest = (7, 7)
Output
6
Why
A knight takes a minimum of 6 optimal moves to travel from top-left to bottom-right corner on an 8x8 board.

Approach

  1. Confirm board size and whether coordinates are 0-indexed or 1-indexed.

Tips

  • What they are testing: Test when start equals destination (should return 0) and positions requiring intricate multi-hop detours.
  • Common mistake: Using DFS instead of BFS; DFS does not guarantee finding the *minimum* shortest path in an unweighted grid graph.

Follow-ups

  • Discuss various corner cases.

Related Microsoft questions

Collected from public candidate posts and coding forums. Updated Nov 2026.