All questions
Showing of 75What is a linked list, and how does it differ from an array?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A linked list chains elements together using nodes. Each node holds a value and a pointer to the next node. The list only knows where its first node lives. To reach any element you follow pointers one hop at a time.
An array stores elements side by side in one contiguous block. That layout lets you jump straight to index 5 by arithmetic. A linked list cannot; reaching position 5 costs O(n) hops. Arrays give O(1) random access, linked lists give O(n).
The tradeoff flips for growth. An array has a fixed block, so growing may mean copying everything. A linked list just allocates a node and rewires a pointer. Choose based on whether you index often or reshape often.
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 ↓
What is the difference between a singly and a doubly linked list?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A singly linked list gives each node one pointer, aimed at the next node. You can only walk forward, from head toward the tail. To reach the previous node you must restart from the head.
A doubly linked list adds a second pointer, aimed at the previous node. Now you can walk both directions. Deleting a node you already hold becomes easy, since you reach its neighbor on each side directly.
That power costs memory. Every node stores an extra pointer, so a million nodes carry a million more references. You also update two links on each insert instead of one. Pick singly when memory is tight and forward-only is enough. Pick doubly when you delete or scan backward often.
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 ↓
What is a stack, and what does LIFO actually mean?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
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 before older work waits underneath.
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 ↓
What is a queue, and what does FIFO actually mean?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A queue is a waiting line. You add items at the back and remove them from the front. Nobody jumps ahead; the order you arrive is the order you leave.
FIFO means first in, first out. The item that waited longest gets served next. A ticket counter works this way. The person at the front, who came earliest, is called first.
This fairness makes queues natural for scheduling and buffering. Print jobs, task runners, and message pipelines process work in arrival order. When order and fairness matter more than recency, a queue fits. It keeps the oldest waiting item from starving behind newer arrivals.
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 ↓
What are the core operations of a stack, and what do they cost?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A stack offers four operations. Push adds an item to the top. Pop removes and returns the top item. Peek reads the top without removing it. IsEmpty reports whether anything is left.
Each of these costs O(1). You only ever touch one end, so nothing shifts or searches. Push and pop just adjust the top position and one value. Peek reads a single slot.
That constant cost is the whole appeal. No matter how many items sit below, the top operations stay instant. This is why stacks handle deep call chains and long undo histories without slowing down.
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 ↓
What are the core operations of a queue, and what do they cost?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A queue offers enqueue, dequeue, front, and isEmpty. Enqueue adds an item at the back. Dequeue removes and returns the item at the front. Front reads that front item without removing it. IsEmpty checks whether any items remain.
Every one of these costs O(1) when built well. You touch only the two ends, front and back, never the middle. A good design keeps a pointer to both ends so neither operation walks the line.
The catch is that phrase, built well. A careless array-backed queue can drift or need shifting. Keeping both ends O(1) takes a ring buffer or a linked list, which later questions cover.
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 ↓
What do insertion and deletion cost in a linked list versus an array?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
Inserting or deleting in a linked list costs O(1) once you hold the right node. You rewire a pointer or two and you are done. Nothing else moves. The rest of the list stays exactly where it sat.
An array behaves differently. To insert or delete in the middle, you must shift every later element over one slot. That shift costs O(n). Only changes at the very end avoid it.
There is a catch worth naming. The linked list is O(1) only after you reach the node. Finding it first still costs O(n) hops. Arrays trade cheap access for expensive reshaping; linked lists do the reverse.
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 ↓
When should you use a linked list instead of an array?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
Reach for a linked list when you reshape more than you index. If you constantly insert and remove at points you already hold, its O(1) splicing wins. Queues, playlists, and edit histories fit this shape.
It also helps when size is unpredictable. A linked list grows one node at a time, with no big block to reserve or copy. You never pay a resize that duplicates the whole collection.
Skip it when you need fast access by position. Arrays give O(1) indexing and pack tightly in memory, which the processor loves. If you mostly read by index, an array almost always wins.
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 ↓
What is a deque, and what can it do that a stack or queue cannot?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A deque, short for double-ended queue, lets you add and remove at both ends. Push and pop work on the front and on the back. It is a queue and a stack fused into one structure.
That is exactly what a plain stack or queue cannot do. A stack only touches one end. A queue adds at one end and removes at the other. Neither gives you free access to both ends at once.
This flexibility earns its keep in real work. Sliding-window scans, work-stealing schedulers, and browser history all lean on both-end access. When a single end is not enough, a deque is the natural next step.
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 ↓
How do you implement a stack, and what data structure backs it?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
You can build a stack on an array or on a linked list. Both keep push and pop at O(1). The choice mostly changes memory behavior, not the contract callers see.
With an array, you track the top index. Push writes at that index and bumps it. Pop reads and steps back. The array grows when full, occasionally copying everything to a bigger block.
With a linked list, the head node is the top. Push adds a new head; pop unlinks it. No copying ever happens, but each node costs an extra pointer.
stack.push(4); // top is now 4
stack.pop(); // returns 4, top restored
Most languages hand you a ready stack through their dynamic array type. Reach for that first.
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 ↓
How do you implement a queue, and what data structure backs it?
Answer it yourself first - out loud, or typed below.
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:
Last attempt -
A queue needs two access points: one end to add, another to remove. You back it with either a linked list holding head and tail pointers, or a ring buffer over a fixed array. With a linked list, you enqueue at the tail and dequeue at the head, both O(1). The tail pointer is what keeps enqueue cheap; without it you would walk the whole list.
Array-backed queues use two indices that chase each other and wrap around the buffer. That gives O(1) operations with far better cache behavior and no per-node allocation. The catch is fixed capacity, so you either grow the array or reject when full.
Pick the ring buffer when throughput and memory locality matter, like network packet handling. Reach for the linked list when the queue must grow without bound and allocation cost is acceptable.
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 ↓
How do you find the Nth element of a linked list, and what does it cost?
What is a node, and what does each node store in a linked list?
Why does a linked list keep a head pointer, and when do you add a tail?
What is a circular linked list, and where is it used?
What everyday problems do stacks naturally solve?
What everyday problems do queues naturally solve?
Why are stacks and queues defined by their operations rather than their storage?
Why is random access slow in a linked list compared to an array?
How does cache locality make arrays faster than linked lists in practice?
What does the extra pointer in a doubly linked list buy you, and what does it cost?
How does a sentinel node remove edge cases from list insertion and deletion?
How do you detect a cycle in a linked list, and what does the idea cost?
What is the idea behind reversing a linked list in place, and its cost?
Why is deleting a node hard when you only have a pointer to it?
What is the real memory overhead of a linked list per element?
When would you back a stack with an array versus a linked list?
When would you back a queue with an array versus a linked list?
Why does a naive array-backed queue waste space, and how do you fix it?
What is a ring buffer, and how do its head and tail wrap around?
How do you implement a deque so both ends stay O(1)?
How do you build a queue from two stacks, and what does it cost?
Why is push on a dynamic-array stack O(1) amortized but not worst case?
What problem shape does a monotonic stack solve at the concept level?
What problem shape does a monotonic queue solve at the concept level?
Where does the call stack fit, and what lives in a stack frame?
What causes a stack overflow, and how deep can recursion go?
When should you replace recursion with an explicit stack?
Why is a queue, not a stack, the right structure for a BFS frontier?
How does a priority queue differ from a plain FIFO queue?
How do skip lists use linked lists to get faster search?
Why is a doubly linked list the backbone of an LRU cache?
How does insertion into a sorted linked list compare to a sorted array?
What makes splicing or splitting linked lists cheap?
Why can't you binary search a linked list efficiently?
How do you implement a stack that returns its minimum in O(1)?
How would you design an undo and redo feature, and why two stacks?
How do you get the maximum over a sliding window using a deque?
How do you build a fixed-capacity LRU cache from a map and a list?
How do schedulers use multiple queues to balance fairness and priority?
How does a work-stealing deque speed up parallel schedulers?
How do you make a queue thread-safe for many producers and consumers?
How would you design a bounded blocking queue?
How does a lock-free queue work, and what makes it so hard?
How do you make a stack thread-safe without serializing every operation?
What happens to a ring buffer when producers outrun consumers?
How does backpressure work when a queue fills faster than it drains?
How would you make a queue durable across process restarts?
How do you shard a queue to scale past one machine's throughput?
How would you design a delayed or scheduled-delivery queue?
What breaks first when one queue must handle a million messages a second?
How do you process a structure whose depth exceeds the stack limit?
How do you free a very long linked list without overflowing the call stack?
What edge cases must a robust doubly linked list implementation handle?
How do you detect and repair a corrupted or self-looping doubly linked list?
How do you safely iterate a linked list while other threads mutate it?
What concurrency hazards come with a shared linked list, and how do you mitigate them?
What cache-miss costs appear when a linked list grows to millions of nodes?
How does an unrolled linked list trade node count for cache performance?
How do intrusive linked lists reduce allocation overhead in systems code?
How do memory allocators use free lists built on linked lists?
What causes memory fragmentation in a long-lived linked list?
How does XOR linking halve pointer memory, and why is it rarely worth it?
When is a linked list still the right choice at large scale?
How do you maintain a linked list of a billion nodes, and what breaks first?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Linked Lists, Stacks & Queues cheatsheet
- 30-second mental model01
- Costs at a glance02
- Linked lists03
- Stacks (LIFO)04
- Queues (FIFO)05
- Deque & priority queue06
- Choosing the right structure07
- Common pitfalls08
- + 2 more inside
64 of 75 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
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.