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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

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
BFS
Symmetry
Infinite grid
Pruning
Chess moves
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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| + ...


Submit Your Answer
Markdown supported