You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and an end position, determine the number of moves it will take to get to the end position.

For example, you are given a grid with sides n=3 described as follows:
. . .
. X .
. . .

Your starting position (sX,sY) = (0,0) so you start in the top left corner. The ending position is (gX,gY)=(1,2) . The path is (0,0->(0,2)->(1,2). It takes 2 moves to get to the goal.

https://www.hackerrank.com/challenges/castle-on-the-grid

 



Author

Write A Comment