Example 1
Input
SkipList 42
insert 3
insert 6
insert 7
insert 9
insert 12
display
search 7
search 10Output
null
null
null
null
null
Level 3: 12
Level 2: 3 12
Level 1: 3 7 12
Level 0: 3 6 7 9 12
true
falseImplement SkipList, a probabilistic sorted data structure that supports fast search, insertion, and deletion by maintaining multiple layers of linked lists with express lanes.
This problem focuses on layered data structure mechanics and correct PRNG-driven level generation.
SkipList(seed)seed is an unsigned 32-bit integer.Each time a new value is successfully inserted (not a duplicate), generate its level as follows:
Advance the PRNG state before using it:
seed = seed * 1103515245 + 12345Compute the level by counting the number of trailing 1-bits in the updated seed, capped at 15.
seed in binary ends in ...0111, the level is 3.seed is 0, the level is 0.1, the level is 15 (capped).The PRNG state is shared across all insertions and advances only on successful inserts (not on duplicates, removes, searches, or displays).
insert(value)value is an int type.value already exists in the skip list, do nothing (do not advance the PRNG).null.remove(value)value is an int type.value from all levels of the skip list.value does not exist, do nothing.null.search(value)value is an int type.true if value exists in the skip list, false otherwise.display()Level {L}: followed by the values on that level in ascending order, space-separated.0 <= seed <= 2^32 - 11 <= value <= 10^510^4 total operations.SkipList 42
insert 3
insert 6
insert 7
insert 9
insert 12
display
search 7
search 10null
null
null
null
null
Level 3: 12
Level 2: 3 12
Level 1: 3 7 12
Level 0: 3 6 7 9 12
true
falseSkipList 42
insert 3
insert 6
insert 7
insert 9
insert 12
display
search 7
search 10null
null
null
null
null
Level 3: 12
Level 2: 3 12
Level 1: 3 7 12
Level 0: 3 6 7 9 12
true
false