Tap here to switch tabs
Problem
Submissions

Problem: Check if a Parentheses String Can Be Valid

Try to solve the Check if a Parentheses String Can Be Valid problem.

Statement

A parentheses string is considered valid if it satisfies any of the following conditions:

  • It is the empty string.

  • It can be written as ABAB, which is the concatenation of AA and BB, where both AA and BB are valid parentheses strings.

  • It can be written as (A)(A), where AA is a valid parentheses string.

You are given a parentheses string s and a binary string locked, both of length n. A character locked[i] indicates whether s[i] can be modified:

  • If locked[i] is '1', you cannot alter s[i].

  • If locked[i] is '0', you can change s[i] to either '(' or ')'.

Return true if it is possible to make s a valid parentheses string, or false otherwise.

Constraints:

  • n == s.length == locked.length

  • 1≤1 \leq n ≤105\leq 10^5

  • s[i] is either '(' or ')'.

  • locked[i] is either '0' or '1'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check if a Parentheses String Can Be Valid

Try to solve the Check if a Parentheses String Can Be Valid problem.

Statement

A parentheses string is considered valid if it satisfies any of the following conditions:

  • It is the empty string.

  • It can be written as ABAB, which is the concatenation of AA and BB, where both AA and BB are valid parentheses strings.

  • It can be written as (A)(A), where AA is a valid parentheses string.

You are given a parentheses string s and a binary string locked, both of length n. A character locked[i] indicates whether s[i] can be modified:

  • If locked[i] is '1', you cannot alter s[i].

  • If locked[i] is '0', you can change s[i] to either '(' or ')'.

Return true if it is possible to make s a valid parentheses string, or false otherwise.

Constraints:

  • n == s.length == locked.length

  • 1≤1 \leq n ≤105\leq 10^5

  • s[i] is either '(' or ')'.

  • locked[i] is either '0' or '1'.