Hello there! Playing around with the code, I found an edge case that is failing and may invalidate the current solution.
tests = []struct {
input string
want bool
}{
{
"******((()",
false,
},
}
This test is failing due to this line. The issue is that we are checking if we have enough asterisk to close the open parenthesis, but we are not checking the position of each element
One workaround would be iterating the input from right to left and computing the same logic we did with the left to right; the code will still be log(n).
Another approach I'm looking into is to use two "pointers" and read from left and right at the same time, moving one of the pointers until we reach an open and close parenthesis (or an asterisk to replace one of them).
WDTY?