Very Easy with O(1) Space 100% beat
\n\n\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n
![image.png](https://assets.leetcode.com/users/images/0dfb2845-8745-4bab-8718-c203aeef374e_1728441523.6718616.png)\n\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minAddToMakeValid(string s) {\n        if(s.empty()) return 0;\n        int lcount = 0, rcount = 0;\n        for(char ch:s){\n            if(ch == \'(\'){\n                lcount++;\n            }\n            else{\n                if(lcount == 0){\n                    rcount++;\n                }\n                else{\n                    lcount--;\n                }\n            }\n        }\n        return lcount+rcount;\n    }\n};\n```
['String', 'Greedy', 'C++']