We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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;
Maximum Element
You are viewing a single comment's thread. Return to all 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
}