Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use backtracking to explore all possible combinations of treating '*' as either '(', ')', or an empty string. If any combination leads to a valid string, return true.
DP[i][j] represents whether the substring s[i:j] is valid.
Keep track of the count of open parentheses encountered so far. If you encounter a close parenthesis, it should balance with an open parenthesis. Utilize a stack to handle this effectively.
How about using 2 stacks instead of 1? Think about it.