Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

Given a square matrix filled with 0, 1, 2, 3. Check whether there is a path possible from the source to destination. You can traverse up, down, right and left. (Check **Your Task **for more details).

**Input:**

The first line of input is an integer **T** denoting the no of testcases. Then T test cases follow. Each test case consists of 2 lines. The first line of each test case contains an integer N denoting the size of the square matrix. Then in the next line are N*N space-separated values of the matrix (M).

**Output:**

Complete **isExist **function and return 1 if the path exists from source to destination else return 0.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **is_possible()** which takes a square matrix (M) and its size (N) as inputs and returns true if there's path possible from the source to destination. Else, it returns false.

You have to start from the Source, traverse through the blank cells and reach the Destination. You can move Up, Down, Right and Left. The description of cells is as follows:

- A value of cell
**1**means Source. - A value of cell
**2**means Destination. - A value of cell
**3**means Blank cell. - A value of cell
**0**means Wall.

**Note**: There are only a single source and a single destination.

**Expected Time Complexity:** O(N^{2}).

**Expected Auxiliary Space:** O(N^{2}).

**Constraints:**

1 <= T <= 100

1 <= N <= 100

**Example:
Input:**

2

4

3 0 0 0 0 3 3 0 0 1 0 3 0 2 3 3

3

0 3 2 3 0 0 1 0 0

**Output:**

1

0

**Explanation:
Testcase 1: **The matrix for the above given input is:

3 0 0 0

0 3 3 0

0

0

From the matrix we can see that there exists a path from to reach destination 2 from source 1.

0 3 2

3 0 0

1 0 0

From the matrix, we can see that there does not exist any path to reach destination 2 from source 1.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Find whether path exist

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.