Remove Invalid Parentheses | Hard
Intuition:
- Use DFS to recursively either remove the character or just continue.
Gotchas:
- The program expects empty string in the answer if there are no other matches
- non-parenthesis characters is like a no-op character, that moves the iterator without doing anything.
- The answer needs to be in set to avoid duplicates
- left parenthesis(L) has a preferential consideration over right parenthesis(R) since R is an invariant if there is more R than L at any given position.
Base case:
- The resulting answer should have a matching number of parenthesis.
- Iteration ends when the iteration reaches the end of …