Minimum Knight Moves

easy
Unit 7 · BFS I0/4 to milestone

A chess knight moves in an L: two squares one way and one square perpendicular. Implement:

  • knight_distance(n, start, target): the minimum number of moves on an n × n board between two (row, col) squares, or -1 if unreachable (small boards can trap the knight)
  • reachable_in(n, start, k): the number of distinct squares reachable in exactly k moves (positions you can be on after k moves; you may revisit squares)
#bfs#grids#chess2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Minimum Knight Moves · TechGradify