Skip to content
Snippets Groups Projects
Select Git revision
  • 34186f32b905ebd7c200cf6582f64237d6a09892
  • master default protected
2 results

cse16238_ex2_qn10.py

Blame
  • cse16238_ex2_qn10.py 433 B
    def maximum(str):
        max = 0
        maxi = 0
        n=len(str)
        for i in range(n):
            if (str[i] == '('):
                max+=1;
                if(max>maxi):
                    maxi=max
            elif (str[i] == ')'):
                if(max > 0):
                    max-=1;
                else:
                    return -1;
        if(max !=0):
            print("Not Valid")
            return -1;
        return maxi;
    str=input("Enter a string")
    print (maximum(str))