Segmentation fault and runtime error in python on submission ?pls check

interview-questions
Tags: #<Tag:0x00007f1827f1fa68>

#1

size=len(a)
stack=[]
openy={ ‘{’:1,’[’:2,’(’:3 }
close={ ‘}’:-1,’]’:-2,’)’:-3 }
for i in range(0,size):
if a[i]==’{’ or a[i]==’[’ or a[i]==’(’:
stack.append(openy[a[i]])
elif a[i]==’}’ or a[i]==’)’ or a[i]==’]’:
if len(stack)==0 or stack[-1]+close[a[i]]!=0 :
return 0
else :
stack.pop()

        else : 
            if len(stack)==0: 
                return 1
                     
            else:
                return 0`Preformatted text`

#2

Faced the same issue, switched to python 2 and the code worked


#3

can anyone please explain why it works with python 2 but not with python 3. i faced similar issue. Thanks!