#3001
Minimum Moves to Capture The Queen
expert · 1225 · lc medium +32 · verified · 22.3% accepted · 183 likes · top 2%
Description
There is a 1-indexed 8 x 8 chessboard with 3 pieces.
You are given 6 integers a, b, c, d, e, f where:
- (a, b) is the white rook's position.
- (c, d) is the white bishop's position.
- (e, f) is the black queen's position.
Moving only white pieces, return the minimum number of moves to capture the black queen.
Rules:
- Rooks move any number of squares horizontally or vertically but cannot jump over pieces.
- Bishops move any number of squares diagonally but cannot jump over pieces.
- A piece captures the queen by moving to its square.
- The queen does not move.
Example 1:
Input: a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
Output: 2
Explanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).
It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.
Example 2:
Input: a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
Output: 1
Explanation: We can capture the black queen in a single move by doing one of the following:
- Move the white rook to (5, 2).
- Move the white bishop to (5, 2).
Code
1
2
3