Design a hash map that supports insertion, lookup, and deletion of integer key-value pairs.
Implement a hash map from scratch with the following operations:
put(key, value): Insert the pair (key, value) into the map. If key already exists, update its value.get(key): Return the value associated with key, or -1 if the key does not exist.remove(key): Delete the key and its value from the map if it exists.Your implementation should behave like a simple associative array for integer keys and values.
Design the data structure so that the operations are efficient on average and handle key collisions correctly.
The interface is called directly by the judge.
put(key, value)get(key)remove(key)All keys and values are integers.
get(key) returns the stored value, or -1 if the key is absent.put and remove do not return a value.Note: Exact official constraints are not provided here; use a standard hash map design approach.
Example 1
Input
put(1, 1) put(2, 2) get(1) get(3) put(2, 1) get(2) remove(2) get(2)
Output
1 -1 1 -1
Explanation
get(1) returns 1.get(3) returns -1 because the key is missing.put(2, 1) updates the existing value for key 2.get(2) returns 1.remove(2), get(2) returns -1.Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.