Google | Check for possible path in 2D matrix

Given a 2D array(m x n), check if there is any path from top left to certain index which is pointed by number 9. In the matrix, 1 is considered as road cell and 0 is considered as no road cell(can’t go through this cell). Return true or false if there is path like the description above.

Input : arr[][] = {
				  {1, 1, 0, 1, 0},
				  {1, 0, 0, 1, 1},
				  {1, 0, 1, 9, 1},
				  {1, 1, 1, 0, 0},
				  {1, 0, 1, 1, 1}}
Output : Yes
Input : arr[][] = {{1, 0, 0, 1, 0},
                  {1, 0, 0, 1, 1},
                  {0, 0, 0, 1, 0},
                  {1, 0, 1, 9, 1},
                  {1, 0, 1, 0, 1}}
Output : No
Comments (4)