Facebook | Phone/Video | Find Cheese

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-05-15Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

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:
* https://leetcode.com/problems/robot-room-cleaner/ (premium)

Comments