O(n) + O(1), count unmatched “]”, beat 100%
Based on some observations, you will find out, the # of switch will be based on count of unmatched \u201C]\u201D,\n\ni.e. \n]][[ -> 1\n]]][[[ -> 2\n]]]][[[[ -> 
Based on some observations, you will find out, the # of switch will be based on count of unmatched \u201C]\u201D,\n\ni.e. \n]][[ -> 1\n]]][[[ -> 2\n]]]][[[[ -> 2\n]]]]][[[[[ -> 2\n```\nclass Solution(object):\n    def minSwaps(self, s):\n        l, r = 0, 0\n        for i in range(len(s)):\n            if s[i] == "]":\n                if l > 0:\n                    l -= 1\n                else: r += 1\n            else: l += 1\n        return r/2 + r%2
[]