Magicsheet logo

Minimum Moves to Capture The Queen

Medium
100%
Updated 6/1/2025

Asked by 2 Companies

Minimum Moves to Capture The Queen

1. What is this problem about?

In this geometry/chess hybrid problem, you are given the positions of three pieces on an 8×88 \times 8 board: a white Rook, a white Bishop, and a black Queen. The Queen doesn't move. You need to find the minimum number of moves to capture the Queen using either the Rook or the Bishop.

The catch? The pieces cannot "jump over" each other. If the Bishop is between the Rook and the Queen, the Rook cannot capture the Queen in one move.

2. Why is this asked in interviews?

Goldman Sachs and Wipro use this to test Conditional Logic and Geometry intuition. It’s not about finding a path using BFS; it’s about checking for "blocks" along horizontal, vertical, and diagonal lines. Key competencies:

  • Case Analysis: Handling horizontal/vertical (Rook) vs. diagonal (Bishop).
  • Collinearity with Obstacles: Checking if point B is on the segment between A and C.
  • Mathematical Simplicity: Realizing the answer is almost always 1 or 2.

3. Algorithmic pattern used

The pattern is Geometric Case Analysis.

  • Rook Capture (1 move): Possible if Rook and Queen share a row or column, AND the Bishop is not directly between them on that same line.
  • Bishop Capture (1 move): Possible if Bishop and Queen share a diagonal, AND the Rook is not directly between them on that same diagonal.
  • Otherwise (2 moves): A Rook can always capture any piece in 2 moves (one move to align the row, one to align the column), assuming no blocks. Since we have two pieces, we can always find a 2-move solution.

4. Example explanation

Rook: (1, 1), Bishop: (1, 4), Queen: (1, 8) Rook and Queen are in the same row (1). But the Bishop is at (1, 4), which is between column 1 and column 8. The Rook is blocked. It cannot capture in 1 move. Can the Bishop capture? It's at (1, 4) and Queen is at (1, 8). Not on a diagonal. So the answer will be 2 moves.

5. Common mistakes candidates make

  • Ignoring the "Block": Forgetting to check if the third piece is in the way.
  • Incorrect Diagonal Check: Not knowing that two points (r1, c1) and (r2, c2) are on the same diagonal if abs(r1 - r2) == abs(c1 - c2).
  • Complex Pathfinding: Using BFS on a chessboard when the pieces have unlimited range. It’s an O(1)O(1) math problem, not a graph problem.

6. Interview preparation tip

Always look for the upper bound. In chess, a Rook can reach any square in 2 moves. A Bishop can reach any square of its color in 2 moves. This limits the possible answers to 1 or 2, which simplifies your task to just checking the "1-move" conditions.

Similar Questions