First we remove one parentheses, check one by one that is there are valid parentheses.
If it don’t have valid parentheses, remove two parentheses at a time.
Then three, four…
So this can approach using BFS method.
In order to avoid duplicate strings being check valid again, we record the last removed position, the next remove position starts from the previous removed position. And if the character is the same as the previous one, we do not remove because it gets the same result.