Loading
Loading
A chess puzzle app places a knight on square (0, 0) of a board that extends forever in every direction. A knight hops two squares in one direction and one square at right angles, giving eight possible hops from any square.
Return the fewest hops that take the knight to square (row, col).
row = 3, col = 3(0,0)start(1,2)hop +1, +2(3,3)hop +2, +12Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Example 2
Example 3
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(d²) time · O(d²) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
One square away in a straight line is surprisingly awkward for a knight: three hops, such as (2, 1), (1, -1)... then (1, 0).