def get_max_depth(string):
    max_depth = 0
    current = 0

    for char in string:
        if char == "(":
            current += 1
            if current > max_depth:
                max_depth = current
        elif char == ")":
            current -= 1

    return max_depth

string = "( ( () ) ( () ) )"
ret = get_max_depth(string)
print(ret)  # 3

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: