### Problem
A knight starts at (0,0) on an infinite board. Each step changes the coordinates by (±2,±1) or (±1,±2). Return the minimum steps to (x,y). The target is guaranteed reachable.
```cpp
class Solution {
public:
int minKnightMoves(int x, int y);
};
```
### Examples
**Example 1:**
```text
Input: x = 1, y = 0
Output: 3
Explanation: One route is(0,0),(2,1),(0,2),(1,0). One move cannot reach the target, and two moves have even coordinate-sum parity, unlike the target.
```
**Example 2:**
```text
Input: x = 0, y = 0
Output: 0
Explanation: The knight already occupies the target.
```
### Constraints
- Both target coordinates are integers in `[-300,300]`.
- `0 <= abs(x)+abs(y) <= 300`.
- The target is reachable on the infinite board.
### Contract considerations
The board is infinite; the numeric bounds limit the target, not permissible intermediate cells.
```hint Read the boundary condition
Must intermediate squares obey the target's numeric bounds, or only the knight's movement rules?
```
### Boundary reminders
The board is infinite; the numeric bounds limit the target, not permissible intermediate cells.
Overview: Minimum Knight Steps on an Infinite Board. A knight starts at(0,0) on an infinite board. Each step changes the coordinates by(±2,±1) or(±1,±2).
A knight starts at (0,0) on an infinite board. Each step changes the coordinates by (±2,±1) or (±1,±2). Return the minimum steps to (x,y). The target is guaranteed reachable.
class Solution {
public:
int minKnightMoves(int x, int y);
};
Examples
Example 1:
Input: x = 1, y = 0
Output: 3
Explanation: One route is(0,0),(2,1),(0,2),(1,0). One move cannot reach the target, and two moves have even coordinate-sum parity, unlike the target.
Example 2:
Input: x = 0, y = 0
Output: 0
Explanation: The knight already occupies the target.
Constraints
Both target coordinates are integers in
[-300,300]
.
0 <= abs(x)+abs(y) <= 300
.
The target is reachable on the infinite board.
Contract considerations
The board is infinite; the numeric bounds limit the target, not permissible intermediate cells.
Boundary reminders
The board is infinite; the numeric bounds limit the target, not permissible intermediate cells.