brackets made of ( and ) and a string pinned of the same length made of 0 and 1. If pinned[i] is 1, the character brackets[i] is pinned and cannot change. If it is 0, either bracket may go in that spot.
A balanced bracket sequence is a non-empty string whose brackets split into pairs: every ( is closed by its own ) to the right, and pairs do not cross (for example (), (()), ()()).
Return True if, by changing only unpinned characters, brackets can be made a balanced bracket sequence, and False otherwise.brackets=")()(", pinned="0110" → TruePositions 0 and 3 are free. Put ( and ) there to get (()).
brackets="())(", pinned="1110" → FalseThe first three characters are pinned, and ()) already has more ) than (, which cannot be fixed.
brackets="(((", pinned="000" → FalseThe length is odd, so no balanced sequence is possible.
brackets consists of ( and )pinned consists of 0 and 1brackets=")()(", pinned="0110"True
Run checks the first 3 tests in your browser. Submit checks all 48 tests on the server, hidden ones included.