← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0]. A knight can move in 8 possible ways: [+/-1, +/-2] and [+/-2, +/-1]. Return the minimum number of steps needed to move the knight to square [x, y]. It is guaranteed the answer exists.
Example 1:
Input: x = 2, y = 1 Output: 1 Explanation: [0, 0] → [2, 1]
Example 2:
Input: x = 4, y = 5 Output: 3
-100000 <= x, y <= 100000d be the Euclidean distance between the starting point and the target, and let m be the Manhattan distance. We know that the knight still must take in steps of either 1 or 2 in the Euclidean distance.m.d moves.1.d, the knight will reach the target in at most d moves.