11049 - Basic wall maze


Difficulty : medium

Solution Description :

BFS problem some extra work

First you need to non reachable node for three wall
input c1 r1 c2 r2
if r1==r2
-----for i=c1+1 to c2
--------- (i,r1+1) not reachable from (i,r1) and (i,r1) not reachable from (i,r1+1)
if c1==c2
----for i=r1+1 to r2
------- (c1+1,i) not reachable from (c1,i) and (c1,i) not reachable from (c1+1,i)

Now run bfs from stating position to end position
for each position(c,r) you got 4 adjacency position (c,r-1), (c,r+1), (c-1,r), and (c+1,r)
if any adjacency position not out of boundary and reachable from (c,r) then it push to queue.