Simple O(N) approach and O(1) space
\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        int i=0,r=s.length(),cnt=0;\n        \n        for(i=0;i<r;i++){\n            if(s[i]==\'[\')
```\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        int i=0,r=s.length(),cnt=0;\n        \n        for(i=0;i<r;i++){\n            if(s[i]==\'[\')\n                cnt++;\n            else if(cnt)\n                cnt--;\n            \n        }\n        \n        return (cnt+1)/2;\n    }\n};\n```
['Greedy', 'C', 'C++']