Problem · Math
Minimum Moves for Two Knights to Meet
Learn this problemProblem statement
Two knights start at coordinates first = [x1, y1] and second = [x2, y2] on an infinite chessboard. They take turns, with the first knight moving first. On a turn, the chosen knight must make one standard knight move: two squares along one axis and one square along the other.
Return the minimum total number of moves until the two knights occupy the same coordinate. If they already share a coordinate, return 0.
Function
minimumKnightMeetingMoves(first: int[], second: int[]) → intExamples
Example 1
first = [0,0]second = [1,2]return = 1The first knight can reach the second knight in one move.
Example 2
first = [0,0]second = [1,0]return = 3The adjacent displacement is the exceptional three-move case.
Example 3
first = [7,-4]second = [7,-4]return = 0The knights already meet.
Constraints
first.length == second.length == 2-10^9 <= first[i], second[i] <= 10^9