• + 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;
    

    }