Your question is Custom Stack or Queue. 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.
How would you implement a custom stack or queue using basic arrays or linked lists?
Implement process_operations(mode, operations), where mode is either "stack" or "queue". Each operation is an array such as ["push", value], ["pop"], ["enqueue", value], or ["dequeue"]. Return the values produced by removal and peek operations in order. Return None for removal or peek operations on an empty structure.
Use a custom implementation rather than Python's built-in queue classes. The structure should support constant-time insertion, removal, and peek operations.
def process_operations(mode, operations):