HackerRank Solution: Maximum Element

Sakshi Singh
1 min readJul 11, 2019

--

(In Python3)

n = int(input())

l=[]

mx=[-999]

for i in range(n):

k=list(map(int,input().split()))

p=k[0]

if(p==1):

n1=k[1]

if(n1>=mx[len(mx)-1]):

mx.append(n1)

l.append(n1)

elif(p==2):

x=l.pop()

if(x==mx[len(mx)-1]):

mx.pop()

else:

print(mx[len(mx)-1])

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sakshi Singh
Sakshi Singh

No responses yet

Write a response