Fundamentals · Medium · Free
When would you choose a linked list over an array in an interview?
FresherFundamentalsProgramming Fundamentals
Array vs linked list
An array stores elements contiguously—O(1) index access, costly insert/delete in the middle. A linked list chains nodes with pointers—O(1) insert/delete at known node, but O(n) to reach index i.
| Need | Prefer | Why |
|---|---|---|
| Random access by index | Array | Cache-friendly contiguous memory |
| Frequent head/tail inserts | Linked list / deque | No shifting elements |
| Binary search | Array | Needs O(1) mid access |
| Memory overhead tiny | Array | No per-node pointer cost |
In Java interviews, say you'd use ArrayList by default and LinkedList only for deque-heavy workloads—not "linked list is always better for insert".