Practice Check if a Parentheses String Can Be Valid
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
For each position i of s, locked[i] = 1 fixes its parenthesis; locked[i] = 0 permits choosing either ( or ). Return whether the resulting string can be balanced, so every closing parenthesis matches an earlier opening one and none remain unmatched. Character positions and string length stay unchanged.
Source: Check if a Parentheses String Can Be Valid on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "))()))", locked = "010100"
true
# Example 2
s = "()()", locked = "0000"
true
# Example 3
s = ")", locked = "0"
false
# Example 4
s = "(((())(((())", locked = "111111010111"
true
Constraints
Related LeetCode Problems
Practice more problems similar to Check if a Parentheses String Can Be Valid.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.