Facebook | Phone/Video | Find Cheese
11837

Given a mouse with 2 APIs in a maze. Design an algorithm to find a cheese in the maze using only the 2 given APIs shown below.

class Mouse {

	/**
	* Moves to one of the directions (left, right, up, down) and returns false if you can't move and true if you can.
	*/
	public boolean move(Direction direction);

	/**
	* Returns true if there is a cheese in the current cell.
	*/
	public boolean hasCheese();

	/**
	* Should return true and leave the mouse at that location or false if we can't find cheese and return the mouse back to where it started.
	*/
	public boolean getCheese() {
		// your code goes here
	}
}

Related problems:

Comments (21)