Problem Statement
On an infinite chessboard, a knight starts at position (0, 0). The knight moves in the standard L-shape: two squares in one direction and one perpendicular, or one square in one direction and two perpendicular. Given target coordinates (x, y), return the minimum number of moves to reach (x, y) from (0, 0). This is typically solved using BFS for shortest path on an unweighted graph, with possible math optimizations.[1][3]
Knight Moves
The eight possible moves from any position (cx, cy) are:
Input/Output Examples
| Input | Output | Explanation |
|-------|--------|-------------|
| x=2, y=1 | 1 | Direct knight move from (0,0) [1] |
| x=5, y=5 | 4 | Example path: (0,0) → (2,1) → (4,2) → (3,4) → (5,5) [3] |
| x=2, y=3 | 3 | Example path: (0,0) → (2,1) → (0,2) → (2,3) [1] | [1][3]
Constraints