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.
We keep the newer elements to be appended to stack as the maximum element since you'll need only the maximum element
defgetMax(operations):# Write your code hereansArr=[]stack=[]forsinoperations:t=int(s[0])ift==2:stack.pop()elift==1:n=int(s[2:])ifstackandstack[-1]>n:stack.append(stack[-1])else:stack.append(n)else:ansArr.append(stack[-1])returnansArr
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 →
We keep the newer elements to be appended to stack as the maximum element since you'll need only the maximum element