706. Design HashMap
Practice Design HashMap for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Build a map from integer keys to integer values without using a built-in hash table.
put(key, value)storesvalueunderkey, replacing any old value.get(key)returns the value stored underkey, or-1if there is none.remove(key)deleteskeyand its value if present.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["MyHashMap","put","put","get","get","put","get","remove","get"]
[[],[1,1],[2,2],[1],[3],[2,1],[2],[2],[2]]
-> [null,null,null,1,-1,null,1,null,-1]
Constraints
- 0 <= key, value <= 10^6
- Up to 10^4 calls in total