WEX payment workflows may need to process operations in last-in, first-out order while quickly identifying the highest-priority pending operation. Implement this stack from scratch using linked nodes, without relying on Python's list as the stack.
The stack must support push, pop, top, and get_max. get_max returns the largest value currently stored, and all four operations must run in O(1) time.
Implement process_stack_operations(operations). Each operation is an array whose first element is an operation name:
["push", value] adds an integer to the top and produces no output.["pop"] removes and returns the top value.["top"] returns the top value without removing it.["get_max"] returns the largest value currently in the stack.Return an array containing results from pop, top, and get_max in their original order. The input will not request a query from an empty stack.
def process_stack_operations(operations):