Skip List from Scratch
Updated
Problem statement
Build a skip list yourself, without a built-in sorted container. A skip list keeps values in sorted order in a linked list, and adds a few extra levels of "express" links that jump over many nodes at once, so a lookup can skip most of the list.
The list holds integers and may hold the same value more than once. Start with an empty list and support three calls:
add(num): insert one copy ofnum.search(target): returntrueif at least one copy oftargetis in the list, otherwisefalse.erase(num): ifnumis in the list, remove exactly one copy of it and returntrue. Otherwise change nothing and returnfalse.
Call i is operations[i] applied to values[i]. Return the results of all search and erase calls, in order. add calls produce no result. If there are no search or erase calls, return an empty array.
The tests check only the results, so any correct structure passes them. Aim for a real skip list with O(log n) expected time per call, where n is the number of values stored.
Function
runSkipList(operations: String[], values: int[]) → boolean[]Examples
Example 1
operations = ["add","add","search","search","add","search","erase","search"]values = [3,8,8,5,5,5,3,3]return = [true,false,true,true,false]After adding 3 and 8, searching 8 gives true and searching 5 gives false. After adding 5, searching 5 gives true. Erasing 3 succeeds, so it gives true, and then searching 3 gives false.
Example 2
operations = ["add","add","erase","search","erase","erase","search"]values = [7,7,7,7,7,7,7]return = [true,true,true,false,false]7 is added twice, so the list holds two copies. The first erase removes one copy (true) and 7 is still found (true). The second erase removes the last copy (true). The third erase finds nothing (false), and so does the search (false).
Example 3
operations = ["erase","search","add","search","add","erase","search"]values = [0,20000,20000,20000,0,0,0]return = [false,false,true,true,false]Erasing from an empty list gives false, and so does searching 20000. After adding 20000 it is found. Adding 0 and then erasing it gives true, and 0 is no longer found.
Constraints
1 <= operations.length <= 3000values.length == operations.length- Each
operations[i]is"add","search"or"erase". 0 <= values[i] <= 2 * 10^4
More OpenAI Phone Screen questions
- Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
- Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
- Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
- Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
- Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
- Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
- Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
- Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Least Frequently Used CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- LFU CacheFreshworks · PHONE SCREENFreshworks interview questions
- LFU Cache with LRU Tie-BreakingRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Skip ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
- LFU CacheCitadel · PHONE SCREENCitadel interview questions
- LFU CacheGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Least Frequently Used Cache SimulatorAdobe · PHONE SCREENAdobe interview questions
- Windowed Key-Value MapConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- LRU CacheAthenahealth · PHONE SCREEN
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions