Python3 solution | O(n) | explained pattern
\'\'\'\nThis problem is easier to solve if you\'ve done "921. Minimum Add to Make Parentheses Valid". If you haven\'t,\n I suggest you to do so because you can 
\'\'\'\nThis problem is easier to solve if you\'ve done "921. Minimum Add to Make Parentheses Valid". If you haven\'t,\n I suggest you to do so because you can use the algorithm from that problem as I did.\n The IDEA: the constrains are very important: "The number of opening brackets \'[\' equals n / 2, and the number of closing brackets \']\' equals n / 2." \n 1. We apply the algorithm fom 921 problem to get the number of parantheses that are not balanced (balanced = "[ ]")\n 2. From what is said in the constrains the number of \'[\' is equal to the number \']\'  resulting -> l == r (l = number of "[", r = number of "]" that are not balanced, ex: "] ] [ ["\n 3. There is a pattern to how many changes you have to do in order to make a string balanced by how many "not balanced" brackets you have, using or "l" or "r":\n```\n#l == number of unbalanced brackets/2          |         number of changes\n#\t\t\t\t\t\t\t  2                |             1          ( l = 2, r = 2)\n#\t\t\t\t\t\t\t3,4                |             2          ( l = 3, r = 3 or l = 4, r = 4)\n#\t\t\t\t\t\t\t5,6                |             3          ( l = 5, r = 5 or l = 6, r = 6)\n#\t\t\t\t\t\t\t7,8                |             4          ( l = 7, r = 7 or l = 8, r = 8)\n#\t\t\t\t\t\t\t9,10               |             5          ( l = 9, r = 9 or l = 10, r = 10)\n#\t\t\t\t\t\t\t11,12              |             6          ( l = 11, r = 11 or l = 12, r = 12)\n```\nand so on...\nIf you like it, please upvote!^^\n ```\nclass Solution:\n    def minSwaps(self, s: str) -> int:\n        l = 0\n        r = 0\n        for i in range(len(s)):\n            if s[i] == \']\':\n                if l == 0:\n                    r += 1\n                else:\n                    l -= 1\n            else:\n                l += 1\n        if l % 2 == 0:\n            res = l // 2\n        else:\n            res = (l+1)//2\n        return res\n```\n\n\'\'\'
['Python', 'Python3']