Minimum Knight Hops to a Target on an Infinite Board
Last updated: November 29, 2026
Quick Overview
A knight starts at (0, 0) on an infinite chessboard. Return the minimum number of knight moves needed to reach (x, y).
Meta
November 29, 20260
0
0 solved
A knight starts at (0, 0) on an infinite chessboard. Return the minimum number of knight moves needed to reach (x, y).
A Meta phone screen BFS question where the board is unbounded, so the candidate must find a safe way to bound the search. Interviewers check the symmetry reduction to the first quadrant and awareness that some optimal routes briefly leave it.
What the Interviewer Expects
- Use BFS since each move costs one
- Reduce to the first quadrant by symmetry
- Allow a small negative margin so paths like (1, 1) work
- Explain why BFS terminates on an infinite board
- Mention bidirectional BFS or a closed form
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What closed form or DP gives the answer for large coordinates?
- How would bidirectional BFS change runtime?
- What if some squares are blocked?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
|x| + |y| <= 300.- Knight moves in the standard L shape.
- Return the minimum number of moves....
High-Level Design
Reflecting across either axis does not change the answer, so solve for (|x|, |y|). BFS from the origin explores outward ring by ring and terminates once it reaches the target, which takes `O((|x| + ...