#K40752. Grid Pathfinding
Grid Pathfinding
Grid Pathfinding
You are given a grid with (n) rows and (m) columns. Each cell in the grid is either free (denoted by '0') or blocked (denoted by '1'). Your task is to determine whether there exists a path from the top-left corner (cell ((1,1))) to the bottom-right corner (cell ((n, m))) by moving in the four cardinal directions (up, down, left, right). The starting and destination cells must be free, and you cannot move into a blocked cell. This is a classic breadth-first search (BFS) problem.
inputFormat
The first line contains two integers (n) and (m) representing the number of rows and columns respectively. Each of the next (n) lines contains a string of length (m) consisting of characters '0' and '1' that represent the grid.
outputFormat
Print a single line with the word 'Yes' if there exists a path from the top-left corner to the bottom-right corner; otherwise, print 'No'.## sample
3 3
000
010
000
Yes