A stack is a pile where you only touch the top. You add items on top with push and take them off the top with pop. The bottom stays untouched until everything above it leaves.
LIFO means last in, first out. The most recently added item is the first one you get back. Think of a stack of plates. You wash the last plate you set down, not the first.
This ordering matters when you must reverse or backtrack. Browser back buttons, undo history, and function calls all rely on it. The newest work gets resolved first, while older work waits underneath.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
What do push, pop and peek cost, and why?All O(1) because each touches only the top. Note that push on a dynamic array is O(1) amortized because the array sometimes has to grow.
How does a stack differ from a queue?Contrast newest-first removal with oldest-first removal, and give a job that needs each, like undo versus a print queue.
How do function calls use a stack?Each call pushes a frame holding its locals and return address, and returning pops it, so the latest call finishes first.
What should pop do when the stack is empty?Name the underflow case and pick a contract, such as throwing an error or returning a sentinel. Add that callers can check for empty first.
What you can say
A stack is a pile where you only ever touch the top, adding items with push and taking them off with pop.
LIFO means last in, first out, so the item you added most recently is the first one you get back.
Picture a stack of plates, where you wash the last plate you set down, and the bottom one waits until everything above it is gone.
That order is what you want when you need to reverse or backtrack, which is why browser back buttons, undo history and function calls all use it.
The catch is that you can't reach anything below the top without popping what sits above it, so if work must be handled in arrival order, a queue fits better.
Weak answers to avoid
Recites the acronym and stopsSaying 'last in, first out' only shows you memorized it. Say the newest item comes back first, then give one case like undo where that order matters.
Mixes up LIFO and FIFOTaking the oldest item first describes a queue. A stack always hands back the item added most recently.
Describes a stack as an arrayA stack is defined by push and pop at one end, and either an array or a linked list can back it. Lead with the behavior and bring up storage only if asked.
Claims you can reach any itemOnly the top is reachable. Anything below waits until the items above it are popped, and that restriction is what produces the LIFO order.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.