Hash Table
Implement a hash table with the following methods:
HashTable()
constructs a new instance of a hash tableput(int key, int val)
updates the hash table such thatkey
maps toval
get(int key)
returns the value associated withkey
. If there is no suchkey
, then return-1
.remove(int key)
removes both thekey
and the value associated with it in the hash table.
This should be implemented without using built-in hash table.
Constraints
n ≤ 100,000
wheren
is the number of calls toput
,get
andremove
https://binarysearch.com/problems/Hash-Table
Examples
Example 1
Input
- methods =
['constructor', 'put', 'get', 'remove', 'get']
- arguments =
[[], [1, 10], [1], [1], [1]]
Output
- answer =
[None, None, 10, None, -1]
Leave a comment