Your question is Max Stack Data Structure. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
An Autodesk Fusion command-history prototype needs a stack that can return its largest stored value without scanning all commands. Implement max_stack(operations) to process stack operations efficiently.
The input is a list of operation arrays. Each operation is either ["push", value], ["pop"], ["top"], or ["peekMax"], where value is an integer. Return a list containing the results of every pop, top, and peekMax operation in their original order. Push operations do not add a result.
The stack stores integers and starts empty. You may assume pop, top, and peekMax are never called when the stack is empty.
def max_stack(operations):