Editorial for Stack


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
summation = 0
stack = None
def top():
    global stack
    return stack[-1]
def pop():
    global stack
    global summation
    summation -= (stack[-1]*stack[-1])
    stack.pop(-1)
    return None
def push(val):
    global stack
    global summation
    stack.append(val)
    summation += (val*val)
    return None
def init():
    global stack
    global summation
    stack = []
    summation = 0
    return None
def getSquareSum():
    global summation
    return summation

Comments

There are no comments at the moment.