Simple to understand O(N) Python solution
Have two counters to keep track, one is for many \'[\' opening_total there are and another is for how many \']\' closing_total there are. If the opening_total i
Have two counters to keep track, one is for many \'[\' `opening_total` there are and another is for how many \']\' `closing_total` there are. If the opening_total is greater than the closing_total, a swap is done where a \'[\' is taken from the end of the array and the \']\' from the current iteration index. This swap is implied and does not need to be coded out. Simply the closing_total will then decrement, the opening_total will increment and the total number of totals will increment by 1. \n```\nclass Solution:\n    def minSwaps(self, s: str) -> int:\n        swaps = 0\n                \n        opening_total = 0\n        closing_total = 0\n        \n        for letter in s:\n            if letter == \']\':\n                closing_total += 1\n            if letter == \'[\':\n                opening_total += 1\n            if closing_total > opening_total:\n                swaps += 1\n                closing_total -= 1\n                opening_total += 1\n            \n        return swaps\n```
['Python']