Given a grid with obstacles, a robot with its starting point(si, sj) and a destination(di, dj), find the minimum steps to the destination from starting point. Provided robot can go in all four directions from starting point but once a direction is chosen it can only change its direction when it hits a boundary. For eg, if it chose left, it will go on in left direction till it hits the boundary, now it will again choose a direction(up or down) and continue till it hits the boundary and so on till it reaches the destination.
Here, boundary is either an obstacle or end of the grid
one step is equal to number of change in directions.
0 0 1 0 0
0 0 0 S 0
0 D 0 1 0
1 1 0 1 1
0 0 0 0 0In this grid, answer will be 2. First move left, hit the the boundary, move down(step 1), hit the obstacle, move left(step 2), reach destination.