Linked Lists, Stacks, Caches, And Pointer Techniques
Asked of: Software Engineer
Last updated

What's being tested
These problems test data-structure design with strict operation-level complexity targets: usually O(1) or O(log n) for get, put, push, pop, peekMax, and removal. Interviewers are probing pointer discipline, reference equality, cache eviction invariants, and whether you can combine structures like hash maps, doubly linked lists, stacks, heaps, and balanced trees cleanly.
Patterns & templates
-
LRU cache =
HashMap<key, Node>+ doubly linked list;getandputmove nodes to front inO(1). -
Pointer-safe list operations need helpers like
remove(node),insertFront(node), and sentinelhead/tailnodes to avoid null-heavy edge cases. -
Linked-list intersection uses two pointers switching heads:
a = a ? a.next : headB; detects shared node by reference inO(m+n)time,O(1)space. -
Max stack variants trade off operations: two stacks give
getMax()inO(1), butpopMax()may requireO(n)temporary movement. -
Efficient
popMax()usually combines a doubly linked list for stack order withTreeMap<Integer, Stack<Node>>for max lookup/removal inO(log n). -
LFU/cache follow-ups require frequency buckets plus recency ordering; track
minFreq, key-to-node map, and freq-to-ordered-nodes map. -
Thread-safety follow-up: protect cache mutations with a lock; mention coarse-grained locking first, then
ReadWriteLockor sharding if contention matters.
Common pitfalls
Pitfall: Comparing linked-list node values instead of node references for intersection; intersection means the exact same object, not equal data.
Pitfall: Claiming
O(1)max removal from a heap without explaining lazy deletion or node handles; standard heaps do not remove arbitrary elements inO(1).
Pitfall: Forgetting to update both structures on every mutation: cache map and linked list, or max index and stack order.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Solve Cache, Window, and Heap ProblemsLinkedIn · Software Engineer · Onsite · medium
- Design a stack with max removalLinkedIn · Software Engineer · Technical Screen · medium
- Implement an LRU cache with follow-upsLinkedIn · Software Engineer · Onsite · medium
- Validate parentheses with one or three bracket typesLinkedIn · Software Engineer · Technical Screen · medium
- Detect intersection of two linked listsLinkedIn · Software Engineer · Technical Screen · Medium
- Design a max-stack with efficient operationsLinkedIn · Software Engineer · Onsite · Medium
- Reverse a linked listLinkedIn · Software Engineer · Onsite · Medium
Related concepts
- Linked Lists, Pointers, Caches, And In-Memory StoresCoding & Algorithms
- Trees, Linked Lists, And Pointer AlgorithmsCoding & Algorithms
- Mutable Data Structures And O(1) DesignCoding & Algorithms
- LRU Cache And O(1) Data StructuresCoding & Algorithms
- Caching And Stateful Data Structure DesignCoding & Algorithms
- Tree And Linked Structure AlgorithmsCoding & Algorithms