#K84072. Safe Path in Hazardous Grid
Safe Path in Hazardous Grid
Safe Path in Hazardous Grid
You are given a square grid of size \( n \times n \) where each cell is either safe ('.') or hazardous ('x'). You start at the top-left corner and your goal is to reach the bottom-right corner. You can move up, down, left, or right, but you can only step on safe cells ('.').
Your task is to determine whether there exists a safe path from the start to the goal. The starting cell and the destination cell must be safe.
Note: The grid is 1-indexed when described, but you will receive it as a list of strings where the first character of the first string is the starting cell and the last character of the last string is the destination.
Constraints: \( 1 \leq n \leq 1000 \).
inputFormat
The first line contains an integer \( n \) representing the size of the grid. The next \( n \) lines each contain a string of length \( n \) consisting of the characters '.' (safe) and 'x' (hazardous), representing the grid.
Example: 3 .x. ..x x..
outputFormat
Print true
if there exists a safe path from the top-left corner to the bottom-right corner, and false
otherwise.
Example Output: true## sample
1
.
true