The strings s and locked have equal length. The string s contains parentheses, and locked contains bits. At index i, a 1 in locked means the parenthesis must stay unchanged; a 0 lets you choose either ( or ) for that position. Return true if some choices make the entire string balanced. In a balanced string, no prefix has more closing than opening parentheses, and the total counts are equal. Characters cannot be inserted or removed.
In the diagrams, filled boxes are locked positions; the digits underneath are the corresponding locked bits.
Example 1:
Input: s = "))"
locked = "00"
Output: trueExplanation: Both positions are unlocked. Change the first character to ( and keep the second as ), giving ().
Example 2:
Input: s = ")("
locked = "11"
Output: falseExplanation: Both characters are locked. The string starts with a closing parenthesis, so it cannot be balanced.
Example 3:
Input: s = "(()"
locked = "000"
Output: falseExplanation: A balanced string must have even length. Changing these three characters cannot change the length, so no valid result exists.
Constraints:
1 <= s.length <= 100000s.length == locked.lengthscontains only(and).lockedcontains only0and1.