Created
August 29, 2016 13:07
-
-
Save mr-karan/49951ea56de3300b34905011fcaab137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self,val=None,curMax=None): | |
self.val = val | |
self.curMax = curMax | |
def __repr__(self): | |
return str(self.data) | |
class Stack(object): | |
def __init__(self): | |
self.items = [] | |
def __str__(self): | |
return "Size is {}".format(len(self.items)) | |
def push(self,data): | |
self.items.append(data) | |
def isEmpty(self): | |
if len(self.items) ==0: | |
return True | |
return False | |
def pop(self): | |
self.items.pop() | |
def top(self): | |
if self.isEmpty(): | |
return None | |
return self.items[-1] | |
def delete(self): | |
self.items[-1].pop() | |
def max(self): | |
return max(self.items) | |
n = int(input()) | |
s = Stack() | |
maxel = 0 | |
for i in range(n): | |
c = input() | |
code = c.split(" ") | |
if code[0] == "1": | |
code1 = int(code[1]) | |
maxel = max(code1,maxel) | |
s.push(Node(code1,maxel)) | |
if code[0] == "2": | |
if(not s.isEmpty()): | |
s.pop() | |
if s.isEmpty(): | |
maxel = 0 | |
else: | |
maxel = s.top().curMax | |
if code[0] == "3": | |
if (not s.isEmpty()): | |
print(s.top().curMax) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment