#K59932. Taco Grid Path
Taco Grid Path
Taco Grid Path
You are given a grid of size (n \times m) consisting of characters '.' and '#'. The character '.' denotes a free cell, and '#' denotes an obstacle. Starting from the top-left cell (first row, first column), determine whether there exists a path to the bottom-right cell (last row, last column) by moving only to the right or down. You cannot move through obstacles.
Note: Both the starting and the ending cells must be free (i.e. '.'), otherwise the answer is immediately "NO".
For example, consider the grid below:
..# .#. ...
A valid path exists from the top-left to the bottom-right cell, so the answer is "YES".
Formally, if we denote the grid as (G) with (G_{i,j}) representing the cell in the (i)-th row and (j)-th column (with 0-based indexing), you are to determine if there exists a sequence of moves starting at (G_{0,0}) and ending at (G_{n-1,m-1}) such that each move goes either one step down or one step right, and every cell in the path is a free cell.
inputFormat
The first line of input contains two integers (n) and (m) (the number of rows and columns, respectively). The next (n) lines each contain a string of length (m) consisting of characters '.' and '#', representing the grid.
outputFormat
Output a single line containing either "YES" if there exists a valid path from the top-left corner to the bottom-right corner, or "NO" otherwise.## sample
3 3
..#
.#.
...
YES