Posted on 22/11/14

Tag :
Algorithm

Let us first analyze the problem..

The problem is to get a path from the top-left corner of the matrix to the bottom-right corner of the matrix..

Some of the blocks of the matrix can't be used in the valid path and are hence marked as '0'..

The cells which can be used to construct a valid path are marked as '1'..

To add, we can go-to any cell adjacent to the present cell, i.e, all the eight adjacent cells, given they are not blocked..

The logic part of the solution is to check every cell for a solution-path which can be constructed through that cell..

Do this recursively and use backtracking to get the path..

Here is the solution-code in

Hope it helps

This blog is like Notes-to-Self and is not intended to teach