Skip to main content
2 of 6
added 51 characters in body
BCdotWEB
  • 11.3k
  • 2
  • 27
  • 45

Where is it slow?

I know many people will say that they are not here to do solve programming for me or may cite the "Open Letter to Students" and belive me I am asking because the discussion forum on HackerRank is dead for me

This is the question:

  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

Ouput the largest number in the Stack

Sample Input:
10
1 97
2
1 20
2
1 26
1 20
2
3
1 91
3

Sample Output:
26
91

My Solution:

data = []
for _ in range(int(input())):
    ins = input().split()
if ins[0] == '1':
    data.append(int(ins[1]))
elif ins[0] == '2':
    data.pop()
else:
    print(max(data))

It gets slow on working with input size of 1000 elements or so

Whats the problem ??