Trains the technique from
LeetCode 1197Minimum Knight MovesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A survey drone parks on an unbounded grid of landing pads, at pad (0, 0). Rows and columns run forever in both directions, so pad coordinates may be negative.
One hop takes the drone from pad (a, b) to any pad that is two rows and one column away, or one row and two columns away: the eight pads (a +- 1, b +- 2) and (a +- 2, b +- 1). There are no obstacles, and the drone may hop to pads outside the rectangle between its parking pad and its target.
Given a target pad (x, y), return the fewest hops that land the drone exactly on it. The target is always reachable.
Example 1
Pad (2, 1) is two rows and one column from the parking pad, so a single hop lands on it.
Example 2
The route (0, 0) to (1, 2) to (3, 3) uses two legal hops and finishes on the target.
Example 3
The route (0, 0) to (-2, 1) to (-1, -1) uses two legal hops and lands on the target.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_knight_moves(x: int, y: int) -> int:public int minKnightMoves(int x, int y)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.