๐ฏ Design a Skip List Data Structure
Imagine having a multi-level highway system for data! A Skip List is a brilliant data structure that achieves O(log n) performance for search, insertion, and deletion operations using nothing more than clever layered linked lists.
Your task is to implement a Skip List from scratch that supports:
- Search: Find if a target value exists
- Add: Insert a new value (duplicates allowed)
- Erase: Remove a value and return success status
The Magic: Unlike traditional linked lists that require O(n) traversal, Skip Lists use multiple levels where higher levels act as "express lanes" to jump over many elements quickly. Each element has a random height, creating a probabilistic balanced structure.
Example: For a Skip List containing [30, 40, 50, 60, 70, 90], adding 45 and 80 would create new nodes that randomly appear in multiple levels, maintaining the sorted order at each level.
Think of it as a linked list with turbo boosters!
Input & Output
Visualization
Time & Space Complexity
Expected O(log n) for all operations due to probabilistic balancing through random heights
Linear space for nodes, with expected O(n) total pointers across all levels
Constraints
- 0 โค num, target โค 2 ร 104
- At most 5 ร 104 calls will be made to search, add, and erase
- Duplicates are allowed in the Skip List
- Performance requirement: Average O(log n) time complexity for all operations