Question presented to candidate: "Explain the difference between an array and a linked list. When would you pick one over the other, and what does each look like in Python? If there is time, sketch a small linked list in Python."
What a strong answer should cover:
- Memory layout: one contiguous block versus separate nodes joined by references.
- Costs: O(1) indexing versus O(n) walking; O(n) front inserts versus O(1) relinking at a node you already hold (and that finding the node is still O(n)).
- Dynamic arrays and amortized O(1) appends; the extra memory per node in a linked list.
- Cache locality as the practical reason arrays usually win.
- Python specifics:
listis a dynamic array (of references), the standard library has no linked list class, andcollections.dequeis the tool for O(1) work at both ends.
Code / implementation expected: Optional โ a small Node class with insert, delete and traversal in Python is a common follow-up.