
Input: a =1, b =1, c =8, d =8, e =2, f =3Output: 2Explanation: 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.

Input: a =5, b =3, c =3, d =4, e =5, f =2Output: 1Explanation: 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).
The rook and bishop can capture the queen in one move if they are aligned and not blocked by the other piece. Otherwise, it may take two moves. We check all possible cases for both pieces, considering blocking and alignment.
classSolution {
public:int minMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) {
// Rook one move
if ((a == e || b == f) &&!((a == c && c == e && ((b < d && d < f) || (b > d && d > f))) || (b == d && d == f && ((a < c && c < e) || (a > c && c > e)))))
return1;
// Bishop one move
if (abs(c - e) == abs(d - f) &&!((abs(a - c) == abs(b - d)) && abs(a - e) == abs(b - f) && ((c < a && a < e) || (c > a && a > e))))
return1;
return2;
}
};
classSolution {
publicintminMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f) {
if ((a == e || b == f) &&!((a == c && c == e && ((b < d && d < f) || (b > d && d > f))) || (b == d && d == f && ((a < c && c < e) || (a > c && c > e)))) )
return 1;
if (Math.abs(c-e) == Math.abs(d-f) &&!((Math.abs(a-c) == Math.abs(b-d)) && Math.abs(a-e) == Math.abs(b-f) && ((c < a && a < e) || (c > a && a > e))))
return 1;
return 2;
}
}
1
2
3
4
5
6
7
8
9
classSolution {
funminMovesToCaptureTheQueen(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int): Int {
if ((a == e || b == f) && !((a == c && c == e && ((b < d && d < f) || (b > d && d > f))) || (b == d && d == f && ((a < c && c < e) || (a > c && c > e)))) )
return1if (kotlin.math.abs(c-e) == kotlin.math.abs(d-f) && !((kotlin.math.abs(a-c) == kotlin.math.abs(b-d)) && kotlin.math.abs(a-e) == kotlin.math.abs(b-f) && ((c < a && a < e) || (c > a && a > e))))
return1return2 }
}
1
2
3
4
5
6
defmin_moves_to_capture_the_queen(a: int, b: int, c: int, d: int, e: int, f: int) -> int:
if (a == e or b == f) andnot ((a == c == e and ((b < d < f) or (b > d > f))) or (b == d == f and ((a < c < e) or (a > c > e)))):
return1if abs(c-e) == abs(d-f) andnot ((abs(a-c) == abs(b-d)) and abs(a-e) == abs(b-f) and ((c < a < e) or (c > a > e))):
return1return2
1
2
3
4
5
6
7
8
9
10
11
impl Solution {
pubfnmin_moves_to_capture_the_queen(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) -> i32 {
if (a == e || b == f) &&!((a == c && c == e && ((b < d && d < f) || (b > d && d > f))) || (b == d && d == f && ((a < c && c < e) || (a > c && c > e)))) {
return1;
}
if ( (c-e).abs() == (d-f).abs() &&!((a-c).abs() == (b-d).abs() && (a-e).abs() == (b-f).abs() && ((c < a && a < e) || (c > a && a > e))) ) {
return1;
}
2 }
}