19. Min Add to Make Parentheses Valid
โ GFG solution to the Min Add to Make Parentheses Valid problem: find minimum parentheses to add using greedy single-pass algorithm. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: s = "(()("
Output: 2
Explanation: There are two unmatched '(' at the end, so we need to add two ')' to make the string valid.Example 2
Input: s = ")))"
Output: 3
Explanation: Three '(' need to be added at the start to make the string valid.Example 3
๐ Constraints
โ
My Approach
Greedy Counting Strategy
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated