Loading problem…
You're building a custom HashMap implementation. This is useful for understanding how hash maps work internally and for implementing custom key-value storage.
Design a HashMap without using any built-in hash table libraries.
Implement the MyHashMap class:
MyHashMap() initializes the object with an empty map.void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists, update the value.int get(int key) returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key.void remove(int key) removes the key and its corresponding value if the map contains the mapping for the key.const map = new MyHashMap();
map.put(1, 1);
map.put(2, 2);
map.get(1); // 1
map.get(3); // -1
map.put(2, 1); // update
map.get(2); // 1
map.remove(2);
map.get(2); // -1This problem models real data structure implementation: