Solution to a Maze Type Problem