DDSA
Advertisement

3001. Minimum Moves to Capture The Queen

Time: O(1)
Space: O(1)

Approach

Check if rook or bishop can reach queen in 1 move without the other piece blocking.

3001.cs
C#
// Approach: Check if rook or bishop can reach queen in 1 move without the other piece blocking.
// Time: O(1) Space: O(1)

public class Solution
{
    public int MinMovesToCaptureTheQueen(int a, int b, int c, int d, int e, int f)
    {
        if (a == e || b == f)
        {
            if (a == e && a == c
            && ((d - b) * (d - f)) < 0)
                return 2;

            if (b == f && b == d
            && (c - a) * (c - e) < 0)
                return 2;
            return 1;
        }

        if (Math.Abs(c - e) == Math.Abs(d - f))
        {
            if (Math.Abs(c - a) == Math.Abs(d - b)
            && ((b - f) * (b - d)) < 0)
                return 2;
            return 1;
        }

        return 2;
    }
}
Advertisement
Was this solution helpful?