Efficient Approach || Better Runtime || C++ || Minimum number of swaps to make the String Balanced
Intuition\n Describe your first thoughts on how to solve this problem. \nHere, we have to make the string Balanced in minimum number of swaps. And also swap the
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere, we have to make the string Balanced in minimum number of swaps. And also swap the brackets at any indicies any number of times.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We store count(inbalanced) and ans(swapping) as 0.\n2. We stores string s to char ch.\n3. If ch as open bracket \'[\', increment count, else decrement count;\n4. If count < 0, increment ans++, and store count as 1.\n5. At, last return ans i.e minimum number of swapping.\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 minSwaps(string s) {\n        \n        int n = s.size();\n        int count = 0;\n        int ans = 0;\n\n        for(char ch : s)\n        {\n            if(ch == \'[\')\n            {\n                count++;\n            }\n            else\n            {\n                count--;\n            }\n            \n            if(count < 0)\n            {\n                ans++;\n                count = 1;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['Two Pointers', 'String', 'Stack', 'Greedy', 'C++']