All problems
Hash Table Dynamic Resize Rehash Count
Problem
Count how many keys are rehashed when a hash table grows dynamically.
The table starts with initial_capacity buckets and doubles whenever inserting one more key would push count / capacity past load_factor. Every resize rehashes all currently stored keys. There are insert_count distinct insertions.
Return the total number of keys rehashed across all resizes.
Hint
Check the load before adding the new key, then resize and rehash the existing count.
Test cases
case 1
in: [4,0.75,10]
expected: 9
case 2
in: [2,1,3]
expected: 2
case 3
in: [10,0.5,5]
expected: 0
case 4
in: [1,0.5,2]
expected: 1
Starter codePython
def rehash_count(initial_capacity, load_factor, insert_count):
# Your code here
pass4 test cases · run your code against them in the editor