• + 1 comment

    My code does not pass the test cases from 17, due to not being time efficient. So could anyone help to make it more efficient.

    My code,

    def getMax(operations): # Write your code here

    n = len(operations);
    
    stackWithAnswersToType3 = []
    
    # if(n >= 1 and n <= pow(10,5)):
    stack = [];
    
    for i in range(n):
        if(operations[i][0] == '1'):
            stack.append(int(operations[i][2:]));
        elif(operations[i] == '2'):
            stack.pop();
        elif(operations[i] == '3'):
            stackWithAnswersToType3.append(max(stack));
    
    return stackWithAnswersToType3;