Mouse and Cheese Reachability
Updated
Problem statement
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[]) → booleanExamples
Example 1
grid = ["..#",".#C","..."]return = trueThe mouse can move down to row 2, cross to column 2, and then move up to the cheese.
Example 2
grid = [".#C","###","..."]return = falseThe blocked cells separate the starting cell from the cheese.
Example 3
grid = ["C"]return = trueThe 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