The hackerrank problem statement is:
You have an empty sequence, and you will be given queries. Each query is one of these three types:
1 -Push the element x into the stack.
2 -Delete the element present at the top of the stack.
3 -Print the maximum element in the stack.
Input Format
The first line of input contains an integer.
The next lines each contain an above mentioned query. (It is guaranteed that each query is valid.)
Constraints:
Output Format
For each type query, print the maximum element in the stack on a new line.
Sample Input
10 1 97 2 1 20 2 1 26 1 20 2 3 1 91 3
Sample Output
26 91
My code:
n=int(input())
class Stack:
def __init__(self):
self.stack1=[]
def push(self,x):
return self.stack1.append(x)
def pop(self):
self.stack1.pop()
return
def maximum(self):
return max(self.stack1)
stack_object=Stack()
for _ in range(n):
a=list(map(int,input().split()))
if a[0]==1:
stack_object.push(a[1])
elif a[0]==2:
stack_object.pop()
else:
print(stack_object.maximum())