6 Lines of Code || O(1) Space || O(N) one pass solution
```\nvar minSwaps = function(str) {\n    let balance = 0,\n        maxClose = 0;\n    for(let s of str){\n        s === \']\'? balance++ : balance--;\n        m
```\nvar minSwaps = function(str) {\n    let balance = 0,\n        maxClose = 0;\n    for(let s of str){\n        s === \']\'? balance++ : balance--;\n        maxClose = Math.max(maxClose, balance);\n    }\n    return Math.ceil(maxClose/2)\n};\n
['JavaScript']