Build an Unrolled Linked List for a Text Buffer With Fast Inserts
Last updated: November 29, 2026
Quick Overview
Implement a sequence of characters as an unrolled linked list, where each node holds a small array of up to B characters. Support get(i), insert(i, ch) and delete(i), splitting full nodes and merging sparse neighbors.
0
0
0 solved
Implement a sequence of characters as an unrolled linked list, where each node holds a small array of up to B characters. Support get(i), insert(i, ch) and delete(i), splitting full nodes and merging sparse neighbors.
A Google onsite design-and-code problem inspired by text buffers in Docs-style editors, where arrays are slow to insert into and plain linked lists waste memory and cache. The interviewer cares about the split and merge invariants and the O(n / B + B) cost argument.
What the Interviewer Expects
- Store up to B items per node and track node sizes
- Locate a position by skipping whole nodes
- Split a node in half when an insert overflows it
- Merge or borrow when a delete leaves a node too empty
- Argue the O(n / B + B) per-operation cost and choose B near sqrt(n) or a cache line
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add a skip index over nodes to make lookups O(log n).
- How would undo and redo work on this structure?
- Compare with a piece table and a rope.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Operations:
get(i),insert(i, ch)for 0 <= i <= size,delete(i). - Each node holds 1..B items (except an empty buffer).
- Better constants than a linked list of characters; cheaper inserts tha...
High-Level Design
Nodes hold a Python list items and a next pointer. To find position i, walk nodes subtracting their sizes until i falls inside one: O(n / B) node hops. Insert into that node's array at the local o...