Design HashMap

EasyArrayHash TableSQL

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]. Return the result as an array.

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:

The result is [null,null,1,-1,null,1,null,-1].

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:

The result is [null,null,100,null,300,null,-1,null,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!