[LeetCode] Minimum Bishop Moves to Reach Target

4034. Minimum Bishop Moves to Reach Target

There is an 8 x 8 empty chessboard with 1-indexed rows and columns.

You are given an array source = [sr, sc] representing the starting position of a bishop, and an array target = [tr, tc] representing the target position.

In one move, the bishop travels one or more squares along a single diagonal direction, staying within the board.

Return the minimum number of moves for the bishop to land exactly on target. If it can never reach target, return -1.

1
2
3
4
5
6
7
class Solution {
public:
int minBishopMoves(vector<int>& source, vector<int>& target) {
if((source[0] + target[0] + source[1] + target[1]) & 1) return -1;
return abs(source[0] - target[0]) == abs(source[1] - target[1]) ? 1 : 2;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/03/PS/LeetCode/minimum-bishop-moves-to-reach-target/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.