Loading...
You are given two knights on an infinite chessboard, standing at integer coordinates (x1, y1) and (x2, y2). A knight move changes one coordinate by 2 and the other by 1, in any of the 8 combinations of signs and axes; the board has no edges, so every move is always available.
In each move, either knight makes one knight move. The knights may move in any order, and one knight may stay put for as long as you like. Return the minimum total number of moves until both knights occupy the same square.
Input: x1 = 0, y1 = 0, x2 = 1, y2 = 2
Output: 1
Explanation: The first knight moves directly onto the second knight's square.
Input: x1 = 0, y1 = 0, x2 = 1, y2 = 0
Output: 3
Explanation: Adjacent squares are three knight moves apart, e.g. (0,0) -> (2,1) -> (0,2) -> (1,0). Splitting the moves between the two knights cannot do better.
Input: x1 = 5, y1 = -7, x2 = 5, y2 = -7
Output: 0
Explanation: The knights already share a square.
x1, y1, x2, y2 ≤300Click "Run" to test with sample cases or "Submit" to run all tests.