Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Check Knight Tour Configuration

XPChallenge Points: 20
levelLevel: Medium

You have an n x n chessboard, and a knight starts at the top-left cell (0,0).
The knight must move in such a way that it visits every cell exactly once, following valid knight moves.

You are given an n x n matrix grid where:

  • Each cell contains a unique number from 0 to n*n - 1.

  • The number in a cell tells which step of the knight’s journey that cell was visited.

Check whether this matrix represents a valid knight tour.
Return true if the knight follows valid moves for every step; otherwise, return false.

Example 1:

Input: grid = [[0,5,8],[7,2,3],[4,9,1]]

Output: true

Explanation:

Starting from 0 → 1 → 2 → ... → 9 follows all valid knight moves.

Example 2:

Input: grid = [[0,4,7],[3,8,1],[6,2,5]]

Output: false

Explanation:

A move in the sequence is not a legal knight move.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result