← 返回 salesforce 的题目列表Minimum Knight Moves on a Chessboard
类型:online_judge
Minimum Knight Moves on a Chessboard
Given an n × n chessboard, a knight start position (sr, sc), and a target (tr, tc), return the minimum number of knight moves required to reach the target. A knight may move by (±2, ±1) or (±1, ±2) and must remain on the board.
Return -1 if the target is unreachable.
Constraints
1 <= n <= 1,000
All coordinates are in [0, n - 1].
Example
Input
8 0 0 7 7
Output
6