*...*..D
.G..*.....
**...**.
.S....*.
........
...G**..
........
.G..*...
Here is 2d array where
S- Source
D-Destination
G-Point must be
This is a simple Breadth First search algorithm problem. This is called flood fill technique which is a type of Breadth First search algorithm. Read it from here. You can also learn the basic Breadth first algorithm from here. This could also be solved by other techniques like Dijkstra or Floyd warshal. But Breadth first search is easier to understand.