dsa · medium
Steps by Knight
GreyOrangeGraphQueue
n×n chessboard, knight at start=[r,c] (1-indexed), target end=[r,c]. Minimum knight moves, or -1 if impossible (always possible on n>=1 except n=2 some cases).
Arguments
n— board size: ann×nchessboard, cells 1-indexedstart— the starting cell or indexend— the target cell or end index
**Example**
`` Input: 6 [4,5] [1,1] Output: 3 ``
Constraints
1 <= n <= 50 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 6 [4,5] [1,1] Expected: 3