def swap_count(s):
    positions = []
    for index, char in enumerate(s):
        if char == "[":
            positions.append(index)

    swaps = 0
    open_count = 0
    next_open_index = 0

    chars = list(s)

    for i, char in enumerate(chars):
        if char == "[":
            open_count += 1
            next_open_index += 1
        else:
            open_count -= 1

        if open_count < 0:
            swaps += positions[next_open_index] - i
            chars[i], chars[positions[next_open_index]] = chars[positions[next_open_index]], chars[i]
            next_open_index += 1
            open_count = 1

    return swaps