Check a Path Through Mutually Connected Street Tiles
Quick Overview
Check a Path Through Mutually Connected Street Tiles. Each grid tile has two street openings:1 left/right,2 up/down,3 left/down,4 right/down,5 left/up,and6 right/up.
Check a Path Through Mutually Connected Street Tiles
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
Each grid tile has two street openings:1 left/right,2 up/down,3 left/down,4 right/down,5 left/up,and 6 right/up. Determine whether a continuous street path connects the top-left tile to the bottom-right. Neighboring tiles connect only when both expose openings toward each other. You cannot change tiles.
```cpp
class Solution {
public:
bool hasValidPath(vector<vector<int>>& grid);
};
```
### Examples
**Example 1:**
```text
Input: grid = [[1,1]]
Output: true
Explanation: The left tile opens right and the right tile opens left.
```
**Example 2:**
```text
Input: grid = [[1],[1]]
Output: false
Explanation: Both tiles have only horizontal openings, so no vertical connection joins them.
```
### Constraints
- The rectangular grid has 1 to 300 rows and 1 to 300 columns.
- Every tile value is in `[1,6]`, with the openings specified above.
### Contract considerations
Keep the grid unchanged; the task asks existence, not the number or length of paths.
```hint Read the boundary condition
Each step needs matching openings on both neighboring tiles. Check boundaries and a grid containing only one tile.
```
### Boundary reminders
Keep the grid unchanged; the task asks existence, not the number or length of paths.
Overview: Check a Path Through Mutually Connected Street Tiles. Each grid tile has two street openings:1 left/right,2 up/down,3 left/down,4 right/down,5 left/up,and6 right/up.
Check a Path Through Mutually Connected Street Tiles
Google
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Each grid tile has two street openings:1 left/right,2 up/down,3 left/down,4 right/down,5 left/up,and 6 right/up. Determine whether a continuous street path connects the top-left tile to the bottom-right. Neighboring tiles connect only when both expose openings toward each other. You cannot change tiles.
class Solution {
public:
bool hasValidPath(vector<vector<int>>& grid);
};
Examples
Example 1:
Input: grid = [[1,1]]
Output: true
Explanation: The left tile opens right and the right tile opens left.
Example 2:
Input: grid = [[1],[1]]
Output: false
Explanation: Both tiles have only horizontal openings, so no vertical connection joins them.
Constraints
The rectangular grid has 1 to 300 rows and 1 to 300 columns.
Every tile value is in
[1,6]
, with the openings specified above.
Contract considerations
Keep the grid unchanged; the task asks existence, not the number or length of paths.
Boundary reminders
Keep the grid unchanged; the task asks existence, not the number or length of paths.