#C654. Robotic Arm Minimum Moves
Robotic Arm Minimum Moves
Robotic Arm Minimum Moves
You are given a grid with M rows and N columns. A robotic arm is positioned at the starting cell (si, sj) and needs to reach the target cell (ti, tj). The robotic arm moves in four cardinal directions (up, down, left, right) and each move changes its position by 1 cell. Your task is to determine the minimum number of moves required for the robotic arm to reach the target position.
Note: The positions are given using 1-indexing. The answer is simply the Manhattan distance between the starting and target positions, computed by:
\( \text{moves} = |ti - si| + |tj - sj| \)
For example, if the robotic arm starts at cell (1,1) and the target is (5,5) in a 5×5 grid, the minimum number of moves is 8.
inputFormat
The input consists of a single line containing six space-separated integers:
- M — the number of rows in the grid
- N — the number of columns in the grid
- si — the starting row position (1-indexed)
- sj — the starting column position (1-indexed)
- ti — the target row position (1-indexed)
- tj — the target column position (1-indexed)
It is guaranteed that the given positions are valid within the grid.
outputFormat
Output a single integer representing the minimum number of moves required for the robotic arm to reach the target position from the starting position.
## sample5 5 1 1 5 5
8