1. Question 1
Given a chessboard of n rows (top to bottom) and n columns (left to right). In each move, a knight moves either:
2 column positions and 1 row position
2 row positions and 1 column position
In other words, a move is 2 steps along one axis and 1 step along a perpendicular axis.
Given a starting position A and ending position B, calculate the minimum number of moves needed by the knight to move from A to B if it is possible. If it is not possible, return -1. All moves must remain within the chessboard.
Example
n = 9
startRow = 4
startCol = 4
endRow = 4
endCol = 8
The chessboard has a size of 9 x 9.
Starts at the position (startRow, startCol) = (4, 4).
- Move 1 step up or down, then 2 steps right to reach either the position (3,6) or (5,6).
- Move 2 steps right and 1 step down or up as...