Design HashMap
Problem statement
Implement an integer-key HashMap and process the given operations in order, starting with an empty map.
For this exercise, each row is [kind,key,value]. Kind 0 puts the key/value pair, replacing any previous value, and returns 0. Kind 1 gets the current value or returns -1 if absent. Kind 2 removes the key if present and returns 0. The third field is ignored for get and remove. Return one answer for every operation.
Build the mapping yourself using arrays or lists; do not use a built-in hash map, dictionary or set. The operation encoding, numeric bounds and acknowledgement values are practice conventions.
Function
runHashMap(operations: int[][]) → int[]Examples
Example 1
operations = [[0,7,11],[1,7,0],[1,8,0],[0,7,4],[1,7,0],[2,7,0],[1,7,0]]return = [0,11,-1,0,4,0,-1]The first put stores 11 at key 7. The missing key 8 returns -1. Replacing key 7 yields 4; removing it makes the last get return -1. Mutations each return 0.
Example 2
operations = [[0,1,9],[0,102,6],[2,1,0],[1,102,0],[1,1,0]]return = [0,0,0,6,-1]Keys 1 and 102 have the same remainder modulo 101 but are distinct. Removing 1 preserves the value 6 at key 102.
Constraints
0 <= operations.length <= 1000operations[i].length == 30 <= operations[i][j] <= 1000000- Operation kinds are 0, 1 or 2; keys are at most 10000.
- Implement the mapping without built-in hash maps, dictionaries or sets. Arrays and lists are allowed.