pattern made of the characters (, ) and *. Each star must, independently, become (, become ), or be deleted.
Return True if the stars can be chosen so that the result is a balanced bracket sequence: every opening bracket has a matching closing bracket to its right, and every closing bracket has a matching opening bracket to its left. The empty string counts as balanced.pattern='(*))' → True
Turn the * into ( and you get "(())".
pattern=')*(' → FalseThe first ) closes something that was never opened, and no choice for the * to its right can fix that.
pattern='*' → True
The star can simply vanish, and the empty string is balanced.
pattern.length ≤ 100pattern[i] is (, ) or *pattern='(*))'
True
Run checks the first 3 tests in your browser. Submit checks all 184 tests on the server, hidden ones included.