[Java] | O(n) | O(1) space | No Stack
Get count of pairs which are not balanced, divide it by 2 as we count them twice.\nReturn ceil value of notBalanced/2.\n\nclass Solution {\n    public int minSw
Get count of pairs which are not balanced, divide it by 2 as we count them twice.\nReturn ceil value of notBalanced/2.\n```\nclass Solution {\n    public int minSwaps(String s) {\n        int notBalancedCount = 0;\n        int open = 0;\n        for(char ch: s.toCharArray()){\n            if(ch == \'[\') open++;\n            else{\n                if(open<=0){\n                    notBalancedCount++;\n                }\n                else open--;\n            }\n        }\n        notBalancedCount+=open;\n        int ans = notBalancedCount/2;\n        return (ans+1)/2;\n    }\n}\n```
['Java']