Max stack

Write codeHard35 minBloomberg style

Your task

Design a max-stack supporting push(x), pop() (remove and return top), top() (peek top), peek_max() (return the maximum), and pop_max() (remove and return the maximum; if there are ties, remove the one closest to the top). Replay operations ["push", x], ["pop"], ["top"], ["peekMax"], ["popMax"] and return the list of values returned by pop/top/peekMax/popMax in order. Assume queries are never made on an empty stack.

Examples

max_stack(ops: list[list]) -> list[int]
Example 1
Inputmax_stack([["push", 5], ["push", 1], ["push", 5], ["top"], ["popMax"], ["top"], ["peekMax"], ["pop"], ["top"]])
Output[5, 5, 1, 5, 1, 5]