Minimum Queen Moves to Reach Target - Solution & Explanation
Problem Statement
There is an 8 x 8 empty chessboard with 1-indexed rows and columns.
You are given an array source = [sr, sc] representing the starting position of a queen, and an array target = [tr, tc] representing the target position.
In one move, the queen travels one or more squares along a single row, column, or diagonal, staying within the board.
Return the minimum number of moves for the queen to land exactly on target.
Example 1:
Input: source = [8,1], target = [1,8]
Output: 1
Explanation:
โโโโโโโ
โโโโโโโ
A single diagonal move takes the queen straight from (8, 1) to (1, 8).
Example 2:
Input: source = [4,2], target = [1,3]
Output: 2
Explanation:
โโโโโโโ
The queen moves from (4, 2) to (4, 3), then from (4, 3) to (1, 3), reaching the target in 2 moves.
Example 3:
Input: source = [1,1], target = [1,1]
Output: 0
Explanation:
The queen is already at the target position, so no moves are needed.
Constraints:โโโโโโโ
source == [sr, sc]target == [tr, tc]1 <= sr, sc, tr, tc <= 8
Solutions for this problem are being prepared.
Try solving it yourselfVideo Solution
LeetCode BiWeekly Contest 192 Q1. Minimum Queen Moves to Reach Target โข ADevOpsEngineer โข 89 views views
Watch 2 more video solutions โReady to solve this problem?
Practice Minimum Queen Moves to Reach Target with our built-in code editor and test cases.
Practice on FleetCodeProblem Info
Table of Contents
Practice this problem
Open in Editor