LearnThatStack Ace your next interview
Linked Lists, Stacks & Queues · question
Question 3 of 78

What is a stack, and what does LIFO actually mean?

beginner
← All Linked Lists, Stacks & Queues questions
Re-explain

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.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Linked Lists, Stacks & Queues One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

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 would you implement a stack, and what would you back it with? Name a dynamic array or a linked list, say which end acts as the top, and explain why that end keeps push and pop O(1).
  • 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

  1. A stack is a pile where you only ever touch the top, adding items with push and taking them off with pop.
  2. LIFO means last in, first out, so the item you added most recently is the first one you get back.
  3. 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.
  4. 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.
  5. 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 stops Saying '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 FIFO Taking the oldest item first describes a queue. A stack always hands back the item added most recently.
  • Describes a stack as an array A 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 item Only 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.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Linked Lists, Stacks & Queues cheatsheet.

← Back to all Linked Lists, Stacks & Queues questions
Pro · $10/mo

67 of 78 Linked Lists, Stacks & Queues answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime