#K61337. Grid Pathfinding
Grid Pathfinding
Grid Pathfinding
You are given a grid with \(N\) rows and \(M\) columns. Each cell in the grid is either an obstacle represented by #
or an empty space represented by .
. Starting from the top-left corner \( (0, 0) \), determine if there exists a path to the bottom-right corner \( (N-1, M-1) \) by moving only right or down.
If a path exists, output YES. Otherwise, output NO. Note that the starting cell and the destination cell must not be obstacles.
inputFormat
The first line contains a single integer (T) denoting the number of test cases. For each test case, the first line contains two space-separated integers (N) and (M). This is followed by (N) lines, each containing a string of length (M) representing the grid. The grid consists of characters #
(obstacle) and .
(empty space).
outputFormat
For each test case, output a single line containing YES
if there exists a valid path from the top-left to the bottom-right corner (moving only right or down), otherwise output NO
.## sample
2
3 3
..#
.#.
...
3 3
..#
##.
...
YES
NO
</p>