Java 2 pointer
\npublic int minSwaps(String s) {\n\tint i=0, j=s.length() - 1, leftCount=0, rightCount = 0, result = 0;\n\twhile(i<j) {\n\t\twhile(leftCount >= 0 && i<j)\n\t\t
```\npublic int minSwaps(String s) {\n\tint i=0, j=s.length() - 1, leftCount=0, rightCount = 0, result = 0;\n\twhile(i<j) {\n\t\twhile(leftCount >= 0 && i<j)\n\t\t\tleftCount = (s.charAt(i++) == \'[\') ? leftCount+1 : leftCount-1;\n\n\t\twhile(rightCount >= 0 && i<j)\n\t\t\trightCount = (s.charAt(j--) == \']\') ? rightCount+1 : rightCount-1;\n\n\t\tif(leftCount == -1) { // swap\n\t\t\tresult++;\n\t\t\tleftCount=rightCount=1;\n\t\t}\n\t}\n\treturn result;\n}\n```
[]