#C6231. Robot Grid Navigation
Robot Grid Navigation
Robot Grid Navigation
You are given a grid consisting of n rows and m columns, represented as a matrix with characters. Each cell is either a free space denoted by .
or an obstacle denoted by #
. The robot starts at the top-left cell, located at position \( (1,1) \), and its goal is to reach the bottom-right cell, located at \( (n,m) \).
The robot can move in the four cardinal directions: up, down, left, and right. It cannot move diagonally, and it cannot step into a cell containing an obstacle. Determine whether the robot can reach the destination.
Input format: The first line contains two integers \( n \) and \( m \) (the dimensions of the grid). The following \( n \) lines each contain a string of length \( m \) representing a row of the grid.
Output format: Output a single line containing YES
if the robot can reach the destination, or NO
otherwise.
inputFormat
The first line contains two space-separated integers, n and m, representing the number of rows and columns, respectively. Each of the next n lines contains a string of length m representing the grid. Cells contain either '.' (free space) or '#' (obstacle).
outputFormat
Output a single line: "YES" if a path from the top-left cell to the bottom-right cell exists, and "NO" otherwise.## sample
4 4
....
.##.
..#.
....
YES