Minimum Knight Moves
A knight starts at square [0, 0] on an infinite chessboard. A knight moves in an L-shape: two squares in one axis and one in the perpendicular axis, giving 8 possible moves. Return the minimum number of moves needed to reach the target square [x, y]. A solution is always guaranteed to exist.
Open official problem prompt ↗Find the smallest number of L-shaped knight jumps that move a piece from the origin to a given target square on an unbounded board.
Think of dropping a stone at the origin in a pond: ripples spread out one ring at a time. Each ring is one more knight move away. The ring that first washes over the target tells you the minimum number of moves.
- Input
- x = 2, y = 1
- Output
- 1
- Why
- A single knight move from [0, 0] lands directly on [2, 1].
-300 <= x, y <= 3000 <= |x| + |y| <= 300