C++ O(n) solution with explanation
e.g. s = "[]][][[]"\nif we iterate over s and maintain a stack like variable c which increses with [ and decreses with ], \nthen at last, if we get c = 0 and c 
e.g. ```s = "[]][][[]"```\nif we iterate over ```s``` and maintain a stack like variable ```c``` which increses with ```[``` and decreses with ```]```, \nthen at last, if we get c = 0 and c >= 0 at any point of traverse, then only ```s``` is valid \nas c<0 means, ```]``` is before ```[```, which is inbalanced string\nbut, here in this problem ,we can be given an imbalanced string as well, so ```c``` can be negative as well.\nthat\'s the same we are suppose to find how much imbalanced it is, i.e. what is the most negative value of ```c``` we can get\ne.g . \n_```][[] ] ] [[```\n```-1010-1-2-10         -> c```\nhere, we are getting ```mx = -2``` as maximum negative value, which we can consider as "parts to repair" in easy words.\nso this much charactors are invalid, hence we can find the number swaps by it,\nas each swaps can repair 2 charactors, \nanswer will be ```ceil(float(abs(mx))/2)```\n\n# Code:\n```\nclass Solution {\npublic:\n    int minSwaps(string s) {\n        int mx = INT_MAX;    // tracker for the most negative value (minimum value) of c\n        int c = 0;\n        for(auto i:s)    \n        {\n            if(i==\'[\') c++;\n            else c--; \n            mx = min(mx, c);\n        }\n        return ceil(double(abs(mx))/2);\n    }\n};\n```
[]