#K83952. Maze Navigation: Iron Man's Odyssey
Maze Navigation: Iron Man's Odyssey
Maze Navigation: Iron Man's Odyssey
Iron Man is trapped in a maze represented as an \( n \times n \) grid. Each cell in the maze is either passable ('.') or contains an obstacle ('#'). Iron Man starts at the top-left corner (cell at row 1, column 1) and his goal is to reach the bottom-right corner (cell at row \( n \), column \( n \)).
Your task is to determine if there exists a path from the starting cell to the destination cell. Iron Man can move to the adjacent cell in the four cardinal directions (up, down, left, right) but cannot move diagonally. The borders of the maze are impassable if there is an obstacle.
Formally, given an integer \( n \) and a maze represented as a list of strings of length \( n \), where each string has exactly \( n \) characters, answer whether there is a path from the top-left cell to the bottom-right cell that only goes through cells marked with ".".
Output YES if Iron Man can reach the destination; otherwise, output NO.
inputFormat
The input is given via standard input (stdin) in the following format:
n maze_row_1 maze_row_2 ... maze_row_n
Here, n
is an integer representing the number of rows (and columns) in the maze. Each maze_row
is a string of length n
consisting of the characters '.' (passable cell) and '#' (obstacle).
outputFormat
Print YES if Iron Man can navigate from the top-left corner to the bottom-right corner. Otherwise, print NO.
The output should be written via standard output (stdout).
## sample4
....
..#.
....
.#..
YES
</p>