We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
stack = list()
sol = list()
max_number = [0]
for i in operations:
if i[0]=='1':
number = int(i[2:])
stack.append(number)
if number >= max_number[-1]:
max_number.append(number)
elif i[0]=='2' and stack:
poppednumber = stack.pop()
if poppednumber==max_number[-1]:
max_number.pop()
elif i[0]=='3':
sol.append(max_number[-1])
return sol
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
Python
Solution
def getMax(operations):