#K8896. Minimum Moves to Reach End
Minimum Moves to Reach End
Minimum Moves to Reach End
You are given a grid with R rows and C columns. Each cell of the grid is either free (represented by a dot '.') or blocked by an obstacle (represented by an asterisk '*'). A robot is initially located at the top-left cell (0-indexed) and needs to reach the bottom-right cell. The robot can move one step at a time in the four cardinal directions (up, down, left, right).
Your task is to determine the minimum number of moves required for the robot to reach the bottom-right cell. If the destination cell is unreachable, output -1.
Note: The starting cell and the destination cell must be free for the robot to be able to start or finish its path.
inputFormat
The input is given via standard input (stdin) in the following format:
R C row1 row2 ... rowR
Where:
R
andC
are the number of rows and columns respectively.- Each of the following
R
lines contains a string of lengthC
representing a row of the grid. Each character is either.
(free cell) or*
(obstacle).
outputFormat
Output via standard output (stdout) a single integer representing the minimum number of moves required for the robot to reach the bottom-right cell. If it is impossible, output -1.
## sample1 1
.
0
</p>