Description

Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class with put(key, value), get(key), and remove(key) methods. Handle collisions appropriately and support keys and values in the range [0, 10^6].

Examples

Input:["put",1,1],["put",2,2],["get",1],["get",3],["put",2,1],["get",2],["remove",2],["get",2]
Output:[null,null,1,-1,null,1,null,-1]
Explanation:

HashMap operations.

Input:["put",5,100],"put",10,200],["get",5],["put",5,300],["get",5],["remove",10],["get",10],["put",15,400],["get",15]
Output:[null,null,100,null,300,null,-1,null,400]
Explanation:

First insert key 5 with value 100 and key 10 with value 200. Getting key 5 returns 100. Update key 5 to value 300, so getting key 5 now returns 300. Remove key 10, so getting key 10 returns -1 (not found). Insert key 15 with value 400, getting it returns 400.

Input:["get",0],["put",0,0],["get",0],["remove",0],["remove",0],["put",1000000,1000000],["get",1000000]
Output:[-1,null,0,null,null,null,1000000]
Explanation:

Getting key 0 from empty HashMap returns -1. Put key 0 with value 0, then get returns 0. Remove key 0, then remove again (no effect since already removed). Insert maximum allowed key-value pair (1000000, 1000000) and retrieve it successfully.

Constraints

  • 0 ≤ key, value ≤ 10⁶
  • At most 10⁴ calls

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!