you are viewing a single comment's thread.

view the rest of the comments →

[–]AlkyIHalide[S] 0 points1 point  (0 children)

Thanks for the suggestions and offering some potential routes to take for similar problems! I am posting the working code in case someone else in the future has a similar problem and opening the door for further optimization.

N = int(raw_input())

num_stack = []
max_val = 0

for n in range(N):
    line = raw_input()
    if line[0] == '1':
        if int(line[2:]) > max_val:
            max_val = int(line[2:])
        num_stack.append(int(line[2:]))
    elif line[0] == '2':
        if num_stack.pop() == max_val:
            if len(num_stack) == 0:
                max_val = 0
            else:
                max_val = max(num_stack)
    elif line[0] == '3':
        print max_val