Problem

Submissions

Solution

New

Discuss

3

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

Suggest Edit

```
1. You have only one key. And a key once used is exhausted and no more available with you during the journey through that path in a maze.
2. A cell with value 1, means the door or path is closed. And you have to spend a key to open the door/ reach that cell.
3. A cell with value 0, means that the cell is free to move / door is always open.
4. Top left cell in the maze and bottom-right cell in the maze may also have a door.
5. Downwards movement: From cell (i, j) to (i, j+1).
6. Rightwards movement: From cell (i, j) to (i+1, j).
```

```
The first line of the input contains an integer 'T' denoting the number of test cases.
Then 'T' test cases follow.
The first line of each test case contains the side length 'N' of the square binary maze.
Then 'N' lines follow.
Each line contains 'N' space-separated integers 1 or 0 denoting whether the cell has a door or not.
```

```
For each test case, print in a separate line “YES” if the bottom right corner is reachable, else print “NO”.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= 'T' <= 100
1 <= 'N' <= 100
'MAZE[i][j]' = {0, 1}
Time Limit: 1 sec
```

```
1
3
0 0 0
1 0 1
0 1 0
```

```
YES
```

```
There are 3 paths possible; two paths have been shown in the below diagram. Note that we are using our only key at the cell (2,3) (1-based indexing).
```

```
1
2
1 0
0 1
```

```
NO
```

Console