def is_balanced(s):
    stack = []
    open_brackets = set({"(", "[", "{"})
    closed_brackets = set({")", "]", "}"})
    open_to_closed = dict({"{": "}", "[": "]", "(": ")"})

    for i in range(len(s)):
        if s[i] in open_brackets:
            stack.append(s[i])

        elif s[i] in closed_brackets and (
            len(stack) == 0 or (len(stack) > 0 and open_to_closed[stack.pop()] != s[i])
        ):
            return False

    return len(stack) == 0