Code failing for following testcase. The code and testcase are given below


#1

class MinStack:
# @param x, an integer
def push(self, x):
if len(min_element_stack)==0:
min_element_stack.append(x)
else:
min_element_stack.append(min(min_element_stack[-1], x))
element_stack.append(x)
def pop(self):
if min_element_stack:
min_element_stack.pop()
if element_stack:
return element_stack.pop()
# @return an integer
def top(self):
if(element_stack):
return element_stack[-1]
else:
return -1

# @return an integer
def getMin(self):
    if min_element_stack:
        return min_element_stack[-1]
    else:
        return -1

element_stack=[]
min_element_stack=[]

It fails for testcase
586 g t t g P 593848644 t p t t t t p P 680232627 P 383101258 P 240914318 g t t g g g p t P 213…


#2

probably because you have not cleared the stack anywhere in your code. for different test cases they are initializing a different class object. but since you have not cleared your stack anywhere, it returns the previous test case value.
you can clear the stack in the constructor itself.

def init(self):
del element_stack[:]
del min_element_stack[:]