Balanced parentheses with wildcards
The string s holds only (, ) and *. Each * can stand for (, for ) or for nothing. Return True if some choice for the stars makes s balanced: every ( is closed by a later ), and no ) appears without an earlier unclosed (.
An empty string is balanced. Aim for one pass and O(1) extra space.
Besides the tests, one large input (a 4,000-character string) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
can_balance("((*)")→truecan_balance("(*)(*)(")→falsecan_balance("*)(*)*)")→truecan_balance(")*(")→false