-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProblem Statement
More file actions
17 lines (14 loc) · 1.2 KB
/
Problem Statement
File metadata and controls
17 lines (14 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
There is a given maze of size N x N. The source and the destination location is top-left cell and bottom right cell respectively.
Some cells are valid to move and some cells are blocked. If one rat starts moving from start vertex to destination vertex,
we have to find that is there any way to complete the path, if it is possible then mark the correct path for the rat.
The maze is given using a binary matrix, where it is marked with 1, it is a valid path, otherwise 0 for a blocked cell.
The rat can only move in two directions, either to the right or to the down.
Your algorithm should take N and NxN matrix which has 1 at the cells which are free and 0 at the cells which are blocked.
An example 5x5 matrix is as follows,
{1, 0, 0, 0, 0} {1, 2, 3, 4, 5}
{1, 1, 0, 1, 0} {6, 7, 8, 9, 10}
{0, 1, 1, 1, 0} with corresponding cell numbers as {11, 12, 13, 14, 15}
{0, 0, 0, 1, 0} {16, 17, 18, 19, 20}
{1, 1, 1, 1, 1} {21, 22, 23, 24, 25}
The solution is (1, 6, 7, 12, 13, 14, 19, 24, 25)
Your program should be able to find a shortest path from source to destination.