"💯 Beats 100% | No Stack Needed 🚫🧳 | Simple C++ Solution 🚀"
Intuition\nThe problem asks for the minimum number of parentheses that need to be added to make a given string of parentheses valid. A string of parentheses is 
# Intuition\nThe problem asks for the minimum number of parentheses that need to be added to make a given string of parentheses valid. A string of parentheses is valid when every open parenthesis $$($$ has a matching close parenthesis $$)$$. The idea is to keep track of unmatched open and close parentheses while iterating through the string.\n\n# Approach\nWe can solve this problem using a linear scan of the string while maintaining two variables:\n\n1. openCount: Tracks how many open parentheses ( are unmatched as we go through the string.\n2. closeCount: Tracks how many close parentheses ) do not have a matching open parenthesis.\n\nFor each character in the string:\n\n* If it is an open parenthesis (, we increment openCount.\n* If it is a close parenthesis ), we check:\n    * If there\'s an unmatched open parenthesis (openCount > 0), we decrement openCount (since we\'ve found a match).\n    * Otherwise, we increment closeCount (since it\'s an unmatched close parenthesis).\n3. At the end of the loop, the sum of openCount and closeCount gives us the minimum number of parentheses we need to add to make the string valid.\n\n\n\n# Complexity\n- Time complexity:\nThe time complexity is $$O(n)$$, where \n$$n$$ is the length of the string. This is because we are iterating through the string exactly once.\n\n- Space complexity:\nThe space complexity is $$O(1)$$ since we are only using two variables (openCount and closeCount) to track the state and are not using any additional space that scales with the input size.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minAddToMakeValid(string s) {\n        int openCount = 0, closeCount = 0;\n        \n        for (char c : s) {\n            if (c == \'(\') {\n                openCount++;\n            } else {\n                if (openCount > 0) {\n                    openCount--;\n                } else {\n                    closeCount++;\n                }\n            }\n        }\n        \n        return openCount + closeCount;\n    }\n};\n\n```
['String', 'Stack', 'Greedy', 'C++']