253. Minimum Knight Moves
Given a chessboard where the knight can move in an "L" shape (two squares in one direction and then one square perpendicular), you are given a starting position (0,0) and a target position (x, y). Find the minimum number of moves required for the knight to reach (x, y).
Example 1:
Input: x = 2, y = 1
Output: 1
Explanation: [0, 0] → [2, 1]
Example 2:
Input: x = 5, y = 5
Output: 4
Explanation: [0, 0] → [2, 1] → [4, 2] → [3, 4] → [5, 5]
Now Your Turn!
Pick the correct output for the given inputInput: x = 3, y = 3
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- -300 ≤ x, y ≤ 300
- 0 ≤ |x| + |y| ≤ 300