Stack Operations
Push: inserts an element at the top.
Pop: removes and returns the top element.
Peek: reads the top element without modifying the stack.
All three are typically O(1).
Pop and Peek should define behavior for an empty stack, such as returning an error or throwing an exception.
How would you implement a simple stack in your preferred language to support push, pop, and peek? Walk me through the code.
If you push elements 1, 2, 3 onto an empty stack and then call pop twice, what values do you get and what's left in the stack?
What would happen if you call pop on an empty stack? How would you handle it?
We have a function that uses a stack to evaluate a postfix expression, but it's throwing an exception on certain inputs. How would you debug the issue related to push/pop usage?
When integrating a stack into a web server request handling pipeline, what trade‑offs would you consider between using a linked‑list based stack versus an array‑based stack?
Suppose you need to add a 'max' operation that returns the current maximum in O(1). How would you extend the basic stack implementation?
Our high‑throughput service uses a stack to manage reusable buffers. At peak load we see increased latency. What stack‑related bottlenecks would you investigate and how would you mitigate them?
Design a thread‑safe stack for a multi‑producer, multi‑consumer scenario. What synchronization primitives would you choose and why?
If the stack needs to persist across process restarts, what changes would you make to the push/pop semantics and storage strategy?
We are migrating a legacy monolith that uses custom stack structures scattered across modules to a microservices architecture. How would you approach consolidating stack behavior while minimizing cross‑team impact?
At a company‑wide level, we want to enforce consistent error handling for stack underflow/overflow across all services. What architectural guidelines and tooling would you propose?
Consider a distributed system where a logical stack spans multiple nodes. What design patterns could you use to maintain LIFO order and consistency, and what trade‑offs do they entail?