Tap here to switch tabs
Problem
Submissions

Problem: Check if There Is a Valid Parentheses String Path

Try to solve the Check if There Is a Valid Parentheses String Path problem.

Statement

You are given an mimesnm imes n grid of characters grid. A path in the grid starts at the top left cell (0,0)(0, 0) and ends at the bottom right cell (m−1,n−1)(m - 1, n - 1). At each step, you can only move either down to cell (r+1,c)(r + 1, c) or right to cell (r,c+1)(r, c + 1) from the current cell (r,c)(r, c).

The parentheses string corresponding to a path is formed by concatenating the characters of all cells visited along the path in the order they are traversed.

Return true if there is a path from (0,0)(0, 0) to (m−1,n−1)(m - 1, n - 1) that forms a valid parentheses string. Otherwise, return false.

A parentheses string is valid if:

  • It is an empty string,

  • It can be written as the concatenation of two valid parentheses strings, or

  • It can be written as '(' followed by a valid parentheses string followed by ')'.

Constraints:

  • m == grid.length

  • n == grid[i].length

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

  • grid[i][j] is either '(' or ')'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check if There Is a Valid Parentheses String Path

Try to solve the Check if There Is a Valid Parentheses String Path problem.

Statement

You are given an mimesnm imes n grid of characters grid. A path in the grid starts at the top left cell (0,0)(0, 0) and ends at the bottom right cell (m−1,n−1)(m - 1, n - 1). At each step, you can only move either down to cell (r+1,c)(r + 1, c) or right to cell (r,c+1)(r, c + 1) from the current cell (r,c)(r, c).

The parentheses string corresponding to a path is formed by concatenating the characters of all cells visited along the path in the order they are traversed.

Return true if there is a path from (0,0)(0, 0) to (m−1,n−1)(m - 1, n - 1) that forms a valid parentheses string. Otherwise, return false.

A parentheses string is valid if:

  • It is an empty string,

  • It can be written as the concatenation of two valid parentheses strings, or

  • It can be written as '(' followed by a valid parentheses string followed by ')'.

Constraints:

  • m == grid.length

  • n == grid[i].length

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

  • grid[i][j] is either '(' or ')'