Minimum Moves to Capture The Queen - Problem
Chess Strategy Challenge: You're controlling the white pieces on a standard 8×8 chessboard to capture the black queen in the minimum number of moves possible.

The board contains exactly 3 pieces:
• A white rook at position (a, b)
• A white bishop at position (c, d)
• A black queen at position (e, f)

Movement Rules:
Rooks move any number of squares horizontally or vertically
Bishops move any number of squares diagonally
• Neither piece can jump over other pieces
• The queen remains stationary

Goal: Return the minimum number of moves needed to capture the queen using optimal strategy.

Input & Output

example_1.py — Direct Rook Attack
$ Input: a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
Output: 2
💡 Note: Rook at (1,1) cannot directly attack queen at (2,3) since they don't share row/column. Bishop at (8,8) also cannot directly attack. Any piece can reach the queen in 2 moves maximum.
example_2.py — Blocked Rook Path
$ Input: a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
Output: 1
💡 Note: Rook at (5,3) and queen at (5,2) are on the same row. Bishop at (3,4) doesn't block this horizontal path, so rook can capture in 1 move.
example_3.py — Direct Bishop Attack
$ Input: a = 4, b = 3, c = 3, d = 4, e = 5, f = 2
Output: 1
💡 Note: Bishop at (3,4) and queen at (5,2) are on the same diagonal (difference of coordinates both equal 2). Rook at (4,3) doesn't block this diagonal path, so bishop can capture in 1 move.

Constraints

  • 1 ≤ a, b, c, d, e, f ≤ 8
  • No two pieces occupy the same position
  • All positions are valid chessboard coordinates
  • The chessboard is standard 8×8 size

Visualization

Tap to expand
Attack Pattern AnalysisRook attacks (horizontal/vertical)Bishop attacks (diagonal)Decision Logic:1. Can rook attack queen directly?• Same row/column? ✓• Path blocked by bishop? ✗2. Can bishop attack queen directly?• Same diagonal? Check |dx| = |dy|• Path blocked by rook? Check each stepResult: 1 move if direct attack possibleOtherwise: 2 moves (guaranteed maximum)
Understanding the Visualization
1
Identify Attack Lines
Rook attacks horizontally/vertically, bishop attacks diagonally
2
Check Path Obstruction
Verify if the other piece blocks the direct attack path
3
Apply 2-Move Guarantee
If no direct attack, any piece can reach target in 2 moves
Key Takeaway
🎯 Key Insight: The answer is always 1 or 2 moves. Either a piece can directly attack the queen (1 move), or it needs to reposition first (2 moves maximum for any chess piece to reach any square).
Asked in
Google 15 Meta 12 Amazon 8 Microsoft 6
42.0K Views
Medium Frequency
~15 min Avg. Time
1.9K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen