#K51612. Minimum Moves to Reach Destination on a Grid
Minimum Moves to Reach Destination on a Grid
Minimum Moves to Reach Destination on a Grid
You are given a grid of size \(N \times M\) along with a starting position \((x_1, y_1)\) and a destination \((x_2, y_2)\). In one move, you can move horizontally, vertically, or diagonally (i.e. one step in any of the eight possible directions). Your task is to compute the minimum number of moves required to travel from the starting position to the destination.
The minimum number of moves is determined by the formula:
[ \text{moves} = \max(|x_2 - x_1|, |y_2 - y_1|) ]
If the starting position is the same as the destination, the answer is 0. It is guaranteed that the destination can always be reached under the given constraints.
inputFormat
The first line contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains six integers: \(N\), \(M\), \(x_1\), \(y_1\), \(x_2\), \(y_2\) separated by spaces, where \(N\) and \(M\) denote the dimensions of the grid and \((x_1, y_1)\) and \((x_2, y_2)\) denote the starting and destination coordinates respectively.
outputFormat
For each test case, output a single line containing one integer: the minimum number of moves required to reach from \((x_1, y_1)\) to \((x_2, y_2)\).
## sample4
5 5 1 1 5 5
3 3 1 1 3 3
4 4 2 2 2 2
5 5 1 1 2 2
4
2
0
1
</p>