Skip to content

Practice Check if There is a Valid Path in a Grid

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1391
LeetCode Problem

Check if There is a Valid Path in a Grid

Problem Statement

Each grid cell contains one street type: 1 connects left and right, 2 up and down, 3 left and down, 4 right and down, 5 left and up, and 6 right and up. Moving between neighboring cells is permitted only when their street openings connect across the shared edge. Without changing any street, determine whether a path exists from (0, 0) to (m - 1, n - 1). Return true if it does and false otherwise.

Source: Check if There is a Valid Path in a Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[2,4,3],[6,5,2]]
Output
true

# Example 2

Input
grid = [[1,2,1],[1,2,1]]
Output
false

# Example 3

Input
grid = [[1,1,2]]
Output
false

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 300
1 <= grid[i][j] <= 6

Related LeetCode Problems

Practice more problems similar to Check if There is a Valid Path in a Grid.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.