Implement a Skip List for an Ordered In-Memory Key Index
Last updated: November 29, 2026
Quick Overview
Implement a skip list of integer keys supporting search, add (duplicates allowed) and erase in expected O(log n) time without using any built-in sorted container.
0
0
0 solved
Implement a skip list of integer keys supporting search, add (duplicates allowed) and erase in expected O(log n) time without using any built-in sorted container.
Google interviewers use this to test whether you can build a probabilistic structure from linked lists, the kind used in memtables of LSM storage engines like those behind Bigtable. They look for correct multi-level pointer updates and a clear expected-cost argument.
What the Interviewer Expects
- Use a head sentinel with a fixed maximum number of levels
- Pick each node's level by coin flips with p = 1/2
- Collect the rightmost node before the key at every level (the update path)
- Splice in or out at each level the node occupies
- Explain expected O(log n) search and O(n) expected space
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 range queries returning all keys in [lo, hi].
- Make it safe for concurrent readers with a single writer.
- Compare with a red-black tree for a memtable.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
search(k): True if k is present.add(k): insert k (duplicates allowed).erase(k): remove one copy, return True if one existed.- Expected O(log n) each....
High-Level Design
A skip list is a stack of sorted linked lists. Level 0 contains every key; each higher level contains a random subset of the level below, roughly half. A search starts at the top of the head sentinel,...