Interview replay
Full round replay — ArrayList vs LinkedList
Timed verbal replay with pass/fail criteria per follow-up.
How to run this
The opener
“When would you use LinkedList instead of ArrayList?”
Budget: 45 seconds. Going long here is itself a fail signal.
Follow-ups
1. “LinkedList is better for inserting in the middle — agreed?”
Testing: The central myth. Will they defend it or measure it?
Scoring
Pass: No. Both are O(n) at an index because add(i, e) walks to i first. Measured on JDK 21 ArrayList is ~23x faster: arraycopy moves contiguous bytes at memory bandwidth, LinkedList takes a cache miss per hop.
Fail: Agrees, or hedges with 'in theory' and stops there.
2. “So when is LinkedList's O(1) insertion actually available?”
Testing: Do they know the difference between holding a node and knowing an index?
Scoring
Pass: When you already hold the position — traversing with a ListIterator and calling its add/remove. Reaching a position by index never qualifies.
Fail: Cannot name a case, or repeats 'in the middle'.
3. “Then use it for a queue?”
Testing: ArrayDeque awareness — Java 6.
Scoring
Pass: No, ArrayDeque. Circular array, both ends are index arithmetic, no node per element. Its Javadoc says it is likely faster than LinkedList as a queue.
Fail: Yes, LinkedList is the queue.
4. “Is iterating a LinkedList slow?”
Testing: Separating iteration from indexed access.
Scoring
Pass: No — for-each uses an iterator and is competitive. An index loop calling get(i) is O(n^2), which is a bug rather than a property of the structure.
Fail: Says iteration is slow, with no mention of index loops.
5. “Which uses more memory, and roughly by how much?”
Testing: Whether they have a number or just a direction.
Scoring
Pass: LinkedList: a Node per element with item plus two pointers, ~24 bytes overhead each, against ~4 bytes per array slot. ArrayList wastes up to ~50% of its capacity after growth, still far less.
Fail: 'LinkedList, because of pointers' with no magnitude.
6. “Does an ArrayList ever release memory when you remove elements?”
Testing: Growth is amortised; shrinking is not automatic.
Scoring
Pass: No. Capacity only grows, around 1.5x per growth. trimToSize() is the only way back and it is not on the List interface.
Fail: Assumes it shrinks.
7. “Difference between Arrays.asList and List.of?”
Testing: A daily-use distinction most people get wrong.
Scoring
Pass: Arrays.asList is a fixed-size view over the array you passed — set() works and writes through, add() throws. List.of is immutable and rejects null elements with an NPE.
Fail: Says both are immutable.
8. “What did Java 21 change here?”
Testing: SequencedCollection, JEP 431.
Scoring
Pass: getFirst/getLast/addFirst/addLast/reversed on List, so ArrayList got the ergonomics LinkedList had. reversed() is a view, and the complexities did not change.
Fail: Nothing / unaware.
Score yourself
← Back to When would you use LinkedList instead of ArrayList?