2596. Check Knight Tour Configuration Medium
1/**
2 * [2596] Check Knight Tour Configuration
3 *
4 * There is a knight on an n x n chessboard. In a valid configuration, the knight starts at the top-left cell of the board and visits every cell on the board exactly once.
5 * You are given an n x n integer matrix grid consisting of distinct integers from the range [0, n * n - 1] where grid[row][col] indicates that the cell (row, col) is the grid[row][col]^th cell that the knight visited. The moves are 0-indexed.
6 * Return true if grid represents a valid configuration of the knight's movements or false otherwise.
7 * Note that a valid knight move consists of moving two squares vertically and one square horizontally, or two squares horizontally and one square vertically. The figure below illustrates all the possible eight moves of a knight from some cell.
8 * <img alt="" src="https://assets.leetcode.com/uploads/2018/10/12/knight.png" style="width: 300px; height: 300px;" />
9 *
10 * <strong class="example">Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2022/12/28/yetgriddrawio-5.png" style="width: 251px; height: 251px;" />
12 * 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]]
13 * Output: true
14 * Explanation: The above diagram represents the grid. It can be shown that it is a valid configuration.
15 *
16 * <strong class="example">Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2022/12/28/yetgriddrawio-6.png" style="width: 151px; height: 151px;" />
18 * Input: grid = [[0,3,6],[5,8,1],[2,7,4]]
19 * Output: false
20 * Explanation: The above diagram represents the grid. The 8^th move of the knight is not valid considering its position after the 7^th move.
21 *
22 *
23 * Constraints:
24 *
25 * n == grid.length == grid[i].length
26 * 3 <= n <= 7
27 * 0 <= grid[row][col] < n * n
28 * All integers in grid are unique.
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/check-knight-tour-configuration/
34// discuss: https://leetcode.com/problems/check-knight-tour-configuration/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn check_valid_grid(grid: Vec<Vec<i32>>) -> bool {
40 false
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_2596() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.