Your question is LIFO Stack With Overflow and Underflow. 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.
A Plexus platform component needs a predictable in-memory LIFO buffer for processing operational events. Implement a fixed-capacity stack that supports adding and removing integer elements while explicitly detecting overflow and underflow.
Write process_stack(capacity, operations), where capacity is a positive integer and operations is a list of commands. Each command is either ['push', value], where value is an integer, or ['pop'].
Use a preallocated array and an integer stack pointer. Do not resize the array, use Python's built-in append, or call list.pop.
Return a list containing one result for each operation:
push returns the string "ok".push against a full stack returns "overflow" and does not change the stack.pop returns the removed integer.pop against an empty stack returns "underflow" and does not change the stack.All successful operations must run in O(1) time.
def process_stack(capacity, operations):