Find Two Non-Conflicting Maze Routes
Problem statement
A rectangular maze contains walls #, open cells ., starts a and b, and destinations A and B. The four labeled cells are distinct and are traversable.
Decide whether there is a four-direction path from a to A and a four-direction path from b to B such that the two paths share no cell. A path may not repeat a cell.
Return true when such a pair of routes exists.
Function
haveDisjointRoutes(maze: String[]) → booleanExamples
Example 1
maze = ["...A",".#..","a..#","b..B"]return = trueThe two agents can use disjoint corridors around the wall.
Example 2
maze = ["aBAb"]return = falseIn the one-row source correction, any routes to the crossing destinations must share a cell.
Example 3
maze = ["a.A","###","b.B"]return = trueEach pair has its own isolated corridor.
Constraints
1 <= rows, columns <= 6.- Every row has equal length and contains only
#,.,a,A,b, orB. - Each of the four labels appears exactly once.