Tap here to switch tabs
Problem
Submissions

Problem: Check if There is a Valid Path in a Grid

Try to solve the Check if There is a Valid Path in a Grid problem.

Statement

You are given an m×nm \times n grid grid. Each cell in grid represents a street segment. The value of grid[i][j] corresponds to one of the following 66 street types:

  • 11: Connects the left cell and the right cell.

  • 22: Connects the upper cell and the lower cell.

  • 33: Connects the left cell and the lower cell.

  • 44: Connects the right cell and the lower cell.

  • 55: Connects the left cell and the upper cell.

  • 66: Connects the right cell and the upper cell.

You begin at the top left cell (0,0)(0, 0) and aim to reach the bottom right cell (m−1,n−1)(m - 1, n - 1). You can move between two adjacent cells if and only if both cells possess street segments that connect to each other.

Return true if there is a valid path from (0,0)(0, 0) to (m−1,n−1)(m - 1, n - 1), or false otherwise.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤300\leq 300

  • 1≤1 \leq grid[i][j] ≤6\leq 6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check if There is a Valid Path in a Grid

Try to solve the Check if There is a Valid Path in a Grid problem.

Statement

You are given an m×nm \times n grid grid. Each cell in grid represents a street segment. The value of grid[i][j] corresponds to one of the following 66 street types:

  • 11: Connects the left cell and the right cell.

  • 22: Connects the upper cell and the lower cell.

  • 33: Connects the left cell and the lower cell.

  • 44: Connects the right cell and the lower cell.

  • 55: Connects the left cell and the upper cell.

  • 66: Connects the right cell and the upper cell.

You begin at the top left cell (0,0)(0, 0) and aim to reach the bottom right cell (m−1,n−1)(m - 1, n - 1). You can move between two adjacent cells if and only if both cells possess street segments that connect to each other.

Return true if there is a valid path from (0,0)(0, 0) to (m−1,n−1)(m - 1, n - 1), or false otherwise.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤300\leq 300

  • 1≤1 \leq grid[i][j] ≤6\leq 6