#K86112. Lisa's Grid Journey
Lisa's Grid Journey
Lisa's Grid Journey
Lisa is trapped in a grid maze and her only way to escape is to move from the top-left cell to the bottom-right cell. The maze is represented by a grid of .
(free cell) and #
(blocked cell). Lisa can only move right or down at each step. Determine if there exists a valid path that allows Lisa to reach her goal.
The grid has R rows and C columns. The starting cell is at the top-left corner (first cell) and the destination is at the bottom-right corner (last cell). A valid move is one that remains within the boundaries of the grid and lands on a free cell.
The problem can be formalized as follows: Given a grid $G$ of dimensions $R \times C$, where each cell $G_{i,j}$ is either \( . \) (free) or \( # \) (blocked), determine if there exists a path from \( (1,1) \) to \( (R,C) \) by only moving right or down.
inputFormat
The first line contains an integer T, the number of test cases. Then for each test case:
- The first line contains two integers R and C, representing the number of rows and columns respectively.
- The following R lines each contain a string of length C representing the maze grid, where '.' denotes a free cell and '#' denotes an obstacle.
outputFormat
For each test case, output a single line containing "YES" if there exists a valid path from the top-left corner to the bottom-right corner, or "NO" otherwise.## sample
5
3 3
...
.#.
...
4 4
....
.#..
.#..
....
2 2
.#
#.
2 2
..
..
3 3
.#.
###
...
YES
YES
NO
YES
NO
</p>