Problem · Hash Table
Custom Hash Map Operations
Learn this problemProblem statement
Implement a custom integer hash map without using a built-in hash-map or dictionary type.
You are given parallel arrays operations and arguments. Process them from left to right on one initially empty map:
puthas arguments[key, value]. Insert the pair, or replace the existing value forkey.gethas arguments[key]. Append the stored value to the answer, or append-1when the key is absent.removehas arguments[key]. Delete the key when present; otherwise do nothing.
Return the values produced by the get operations, in operation order. Your implementation must resolve hash collisions by comparing keys, not by assuming each key has a unique bucket.
Function
runHashMap(operations: String[], arguments: int[][]) → int[]Examples
Example 1
operations = ["put","put","get","put","get","remove","get"]arguments = [[1,10],[2,20],[1],[1,15],[1],[2],[2]]return = [10,15,-1]The first get(1) returns 10. Updating key 1 changes its value to 15. After key 2 is removed, get(2) returns -1.
Example 2
operations = ["put","get","remove","remove","get"]arguments = [[0,0],[0],[0],[0],[0]]return = [0,-1]A stored value of 0 is distinct from a missing key. Removing an already absent key has no effect.
Constraints
1 <= operations.length <= 100000operations.length == arguments.length- Each operation is exactly
put,get, orremove. putrows contain exactly two integers; other rows contain exactly one.0 <= key <= 10^90 <= value <= 10^9