[LeetCode] Even Number of Knight Moves

3996. Even Number of Knight Moves

You are given two integer arrays start and target, where each array is of the form [x, y] representing a cell on a standard 8 x 8 chessboard.

Return true if a knight can move from start to target in an even number of moves. Otherwise, return false.

Note: A valid knight move consists of moving two squares in one direction and one square perpendicular to it. The figure below illustrates all eight possible moves from a cell.

1
2
3
4
5
6
class Solution {
public:
bool canReach(vector<int>& start, vector<int>& target) {
return ((start[0] + start[1] - target[0] - target[1]) & 1) == 0;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/03/PS/LeetCode/even-number-of-knight-moves/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.