Loading problem…
This problem builds on valid-parentheses-ii. Complete that first, then load your solution to continue.
You're building an advanced code validator that needs to check if a string with locked and unlocked parentheses can be made valid by swapping unlocked parentheses.
Given a string s and a string locked, both of length n. s[i] is either '(' or ')', and locked[i] is either '0' or '1':
locked[i] is '1', you cannot change s[i]locked[i] is '0', you can change s[i] to either '(' or ')'Return true if you can make s a valid parentheses sequence, otherwise return false.
canBeValid("))()))", "010100");
// true
// Swap unlocked positions to get "()()()"
canBeValid("()()", "0000");
// true
// All positions unlocked, can rearrange to "()()"
canBeValid(")", "0");
// false
// Single ')' cannot be made valid
canBeValid("((()))", "111111");
// true
// All locked, already validThis problem models advanced code validation features: