Description
Given an n x n chessboard with a valid knight's tour marked 0 to n²-1, verify if it represents a valid knight tour.
Examples
Input:
grid = [[0,11,16,5,20],[17,4,19,10,15],[12,1,8,21,6],[3,18,23,14,9],[24,13,2,7,22]]Output:
trueExplanation:
Valid knight tour.
Input:
grid = [[1]]Output:
trueExplanation:
Minimal case with a single-element matrix.
Input:
grid = [[8,1,6],[3,5,7],[4,9,2]]Output:
falseExplanation:
The grid does not represent a valid knight tour because consecutive positions in the sequence are not all reachable by valid L-shaped knight moves.
Constraints
- •
n == grid.length