FastPrepMouse and Cheese Reachability
Problems/Mouse and Cheese Reachability

Mouse and Cheese Reachability

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report gives the start coordinate, helper calls that move and check the goal, and the aim of finding out if the goal can be reached. It leaves out the finite world and the movement rules. Here, we use a grid with limits. Our version is about 78% the same as the reported question.

A mouse starts at coordinate (0, 0) in a finite rectangular environment. The environment is given as grid:

  • '.' is an open cell.
  • '#' is a blocked cell.
  • 'C' is the unique open cell containing cheese.

A movement oracle move(x, y) accepts only an orthogonally adjacent absolute coordinate. It returns false and leaves the mouse in place when that coordinate is blocked or outside the grid; otherwise it moves the mouse and returns true. A goal oracle reachCheese() returns whether the current cell contains the cheese.

Return whether some sequence of successful oracle moves can reach the cheese. The grid gives exactly the same results as those calls, so you can compute the answer directly from it.

Function

canReachCheese(grid: String[]) → boolean

Examples

Example 1

grid = ["..#",".#C","..."]return = true
grid
0120..#1.#C2...

The mouse can move down to row 2, cross to column 2, and then move up to the cheese.

Example 2

grid = [".#C","###","..."]return = false
grid
0120.#C1###2...

The blocked cells separate the starting cell from the cheese.

Example 3

grid = ["C"]return = true
grid
00C

The mouse begins on the cheese, so no movement is needed.

Constraints

  • 1 <= grid.length <= 500.
  • 1 <= grid[0].length <= 500.
  • Every row has the same length.
  • Every cell is '.', '#', or 'C'.
  • grid[0][0] is open or contains cheese.
  • Exactly one cell contains 'C'.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
  • Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions
  • Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Number of IslandsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsCrowdstrike · ONSITE INTERVIEWCrowdstrike interview questions
  • Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions

Interview reports that mention this question

  • Meta Software Engineer Onsite Questions: 3 Experiences

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public boolean canReachCheese(String[] grid) {
        // Write your code here.
    }
}
Checking account…