Practice Design Skiplist
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Implement Skiplist without a built-in skiplist library. search(target) tests membership, add(num) inserts an occurrence, and erase(num) removes one occurrence and returns true, or false if absent. Duplicate values are allowed. Expected operation time is O(log n) and expected storage O(n). Practice approach: Maintain sorted linked levels with randomized node heights. Search from the highest level, recording predecessors at each level before insertion or deletion. Erasing one duplicate must leave other occurrences searchable. Test empty searches and two equal insertions followed by one deletion.
Source: Design Skiplist on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["Skiplist","add","add","search","erase","search","erase","search","erase"] [[],[4],[4],[4],[4],[4],[4],[4],[4]]
[null,null,null,true,true,true,true,false,false]
After one deletion, a second 4 remains. Removing the final occurrence makes search false and another erase fails.
Constraints
Related LeetCode Problems
Practice more problems similar to Design Skiplist.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.