Minimum Knight Moves
CodingOASoftware EngineerReported Mar, 2026
Examples
Example 1:
Input: x = 2, y = 1
Output: 1
Example 2:
Input: x = 5, y = 5
Output: 4
Example 3:
Input: x = 0, y = 0
Output: 0
Explanation:
Example 1:
Input: x = 2, y = 1
Output: 1
Example 2:
Input: x = 5, y = 5
Output: 4
Example 3:
Input: x = 0, y = 0
Output: 0
Explanation:
In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0].
A knight can move in 8 possible ways: [+/-1, +/-2] and [+/-2, +/-1].
Return the minimum number of steps needed to move the knight to square [x, y]. It is guaranteed the answer exists.
The knight starts at the target square.
-300 <= x, y <= 3000 <= |x| + |y| <= 300Reported as a LeetCode-style OA question for software engineer candidates.