Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: A knight starts at square (0,0) on an infinite chessboard. What is the minimum number of knight moves needed to reach square (4,5)?

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

BFS on the knight's move graph gives the minimum number of moves; the parity of the square colour alone does not decide the count. Using the Manhattan distance divided by 3 is a common but wrong shortcut.

More Coding Interview Problems questions

Exams that ask this topic