Skip to content

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.

Hard#1206
LeetCode Problem

Design Skiplist

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

Input
["Skiplist","add","add","search","erase","search","erase","search","erase"]
[[],[4],[4],[4],[4],[4],[4],[4],[4]]
Output
[null,null,null,true,true,true,true,false,false]
Explanation

After one deletion, a second 4 remains. Removing the final occurrence makes search false and another erase fails.

Constraints

0 <= num, target <= 2 * 10^4
At most 5 * 10^4 total method calls.

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.