Sort by

recency

|

1467 Discussions

|

  • + 0 comments

    Python

    Solution

    def getMax(operations):

    stack = list()
    sol = list()
    max_number = [0]
    
    for i in operations:
        if i[0]=='1':
            number = int(i[2:])
            stack.append(number)
            if number >= max_number[-1]:
                max_number.append(number)
    
        elif i[0]=='2' and stack:
            poppednumber = stack.pop()
            if poppednumber==max_number[-1]:
                max_number.pop()
    
        elif i[0]=='3':
            sol.append(max_number[-1])
    
    return sol
    
  • + 0 comments

    Why programmer using C, uploaded code and did not use the fonction in the online editor on the site

  • + 2 comments

    **This is the code of javascript **

    function getMax(operations) { const stack = []; // Initialize an empty stack const maxs = []; // To store maximum elements for type 3 queries

    operations.forEach((op) => {
        if (op === '2') {
            // Delete the element present at the top of the stack
            stack.pop();
        } else if (op === '3') {
            // Print the maximum element in the stack
            const max = Math.max(...stack);
            maxs.push(max);
        } else {
            // Push the element x into the stack
            stack.push(Number(op.slice(2)));
        }
    });
    
    return maxs;
    

    }

  • + 0 comments

    **This is the code of javascript **

    function getMax(operations) { const stack = []; // Initialize an empty stack const maxs = []; // To store maximum elements for type 3 queries

    operations.forEach((op) => {
        if (op === '2') {
            // Delete the element present at the top of the stack
            stack.pop();
        } else if (op === '3') {
            // Print the maximum element in the stack
            const max = Math.max(...stack);
            maxs.push(max);
        } else {
            // Push the element x into the stack
            stack.push(Number(op.slice(2)));
        }
    });
    
    return maxs;
    

    }

  • + 0 comments

    How is it possible that when I run code for a test case and it is successful, but when submit the code, the result for the same test case is unsuccessful?!!