Interview Questions

243. You are in a maze, and you open your eyes so you ....

Microsoft Interview Questions and Answers


(Continued from previous question...)

243. You are in a maze, and you open your eyes so you ....

Question:
You are in a maze(like a labyrinth), and you open your eyes so you don't know your position. The maze has walls and you can move only in up, right, left and down directions. You can escape the maze when you find a ladder.
The following API is given:
bool TryMove(direction) - returns true when you don't hit a wall;
bool HasLadder() - return true if you found the ladder.
Write a method bool Explore() that returns true if you can escape the maze, false otherwise. Also, provide test cases.


maybe an answer:


Labyrinth and maze are two fundamental different things, while a labyrinth has no branching walls, a maze can have. so in labyrinth you need not to check visited if you keep on moving in one direction. check wiki for labyrinth defination and differance with a maze. so probably maze like labyrinth was a hint. Assuming you have a ladder placed in labyrinth.
as the test cases asked checks for it.

while(! FoundLadder())
{
TryMove(Right)
}
TryMove(UP).
Test cases:
null maze - true/false - depends on the business
empty/no wall maze - false,
no ladder maze - false,
maze with solution - true,
maze with laddeds trapped - false,

(Continued on next question...)

Other Interview Questions