Skip to content
Snippets Groups Projects
Select Git revision
  • 2a8e85930ef283fe2e87ec604da43db8c3c29d62
  • master default
2 results

ScrollingActivity.java

Blame
  • cse16218_ex2_10.py 509 B
    def depth(s, n): 
        current_max = 0
        final_max = 0
        
        for i in range(n): 
            if s[i] == '(': 
                current_max += 1
      
                if current_max > final_max: 
                    final_max = current_max 
            elif s[i] == ')': 
                if current_max > 0: 
                    current_max -= 1
                else: #unbalanced
                    return -1
                    
        if current_max != 0: #unbalanced
            return -1
      
        return final_max
      
    s = input()
    print (depth(s, len(s)))