# 2596. Check Knight Tour Configuration ###### tags: `Leetcode` `Medium` `Simulation` Link: https://leetcode.com/problems/check-knight-tour-configuration/description/ ## Code ```python= class Solution: def checkValidGrid(self, grid: List[List[int]]) -> bool: posMap = dict() n = len(grid) for i in range(len(grid)): for j in range(len(grid)): posMap[grid[i][j]] = [i, j] prev = [0, 0] for i in range(n*n): if i==0: if posMap[i][0]!=prev[0] or posMap[i][1]!=prev[1]: return False else: xdiff = abs(posMap[i][0]-prev[0]) ydiff = abs(posMap[i][1]-prev[1]) if not ((xdiff==2 and ydiff==1) or (xdiff==1 and ydiff==2)): return False prev = posMap[i] return True ```