#C12814. Grid Path Finder
Grid Path Finder
Grid Path Finder
You are given a 2D grid consisting of integers 0 and 1, where 0 represents a free cell and 1 represents an obstacle. Your task is to determine whether there exists a path from the top-left cell to the bottom-right cell by moving horizontally or vertically (up, down, left, or right).
Formally, given a grid (G) of size (M \times N), determine if there exists a sequence of moves from cell ((0,0)) to cell ((M-1, N-1)) such that every moved-to cell (including the start and end) contains 0.
inputFormat
The first line contains two space‐separated integers (M) and (N), representing the number of rows and columns. Each of the following (M) lines contains (N) space‐separated integers (either 0 or 1) representing a row of the grid.
outputFormat
Output a single line: either True
if there exists a path from the top-left to the bottom-right cell, or False
otherwise.## sample
4 4
0 0 1 0
0 0 0 0
1 0 1 0
0 0 0 0
True