← 返回 meta 的题目列表Knight Movement Variation
类型:online_judge
Given an infinite chessboard without obstacles, a knight starts moving from the origin (0, 0). Calculate the minimum number of moves required for the knight to reach the target point (x, y). Implement the function def min_knight_moves(x: int, y: int) -> int. Provide unit tests and consider all possible movements of the knight.
Example:
Input: x = 2, y = 1
Output: 1
Explanation: The knight can move directly from (0, 0) to (2, 1).
Input: x = 5, y = 5
Output: 4
Constraints: -300 <= x, y <= 300. Ensure high performance.
Example
Input
2 1