Question: 
Write a function to find out the minimum no of swaps required for bracket balancing in the given string.


Model's Code:
def swap_count(s):
    balance = 0
    swaps = 0
    
    for char in s:
        if char == '[':
            balance += 1
        else:
            balance -= 1
        
        if balance < 0:
            swaps += 1
            balance = 1
            
    return swaps + balance // 2



Sample Correct Code:
def swap_count(s):
	chars = s
	count_left = 0
	count_right = 0
	swap = 0
	imbalance = 0; 
	for i in range(len(chars)):
		if chars[i] == '[':
			count_left += 1
			if imbalance > 0:
				swap += imbalance
				imbalance -= 1
		elif chars[i] == ']':
			count_right += 1
			imbalance = (count_right - count_left) 
	return swap


Asserts:
assert swap_count("[]][][") == 2
assert swap_count("[[][]]") == 0
assert swap_count("[[][]]][") == 1


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: FAIL: AssertionError()

Test 386 of 974: 278/386 (72.02072538860104%): failed