FastPrepImplement an Unordered Map

Implement an Unordered Map

Old Mission logoOld Mission● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Implement an integer key-value map without using a language-provided map, dictionary, or hash-table type.

Process the operations in order:

  • put with arguments [key, value] inserts the key or replaces its current value.
  • get with arguments [key] appends the current value to the result, or -1 when the key is absent.
  • remove with arguments [key] erases the key when it is present and otherwise does nothing.

Return the results of the get operations in their original order.

Your implementation should use hashing, resolve collisions correctly, and provide expected constant-time operations.

Function

runUnorderedMap(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 makes the next lookup return 15. After removing key 2, its lookup returns -1.

Example 2

operations = ["get","put","put","get","remove","get"]arguments = [[-5],[-5,7],[11,4],[-5],[-5],[-5]]return = [-1,7,-1]

Negative keys are valid. The missing key first produces -1, then stores 7, and becomes absent again after removal.

Constraints

  • 1 <= operations.length == arguments.length <= 200000
  • Each operation is put, get, or remove.
  • A put argument has length 2; the other argument arrays have length 1.
  • -10^9 <= key <= 10^9
  • 0 <= value <= 10^9
  • Do not use a built-in map, dictionary, or hash-table implementation.

More Old Mission problems

See Old Mission hiring insights
public int[] runUnorderedMap(String[] operations, int[][] arguments) {
  // Write your code here.
}
operations["put","put","get","put","get","remove","get"]
arguments[[1,10],[2,20],[1],[1,15],[1],[2],[2]]
expected[10,15,-1]
Checking account…