Problem · Hash Table

Design HashMap

Learn this problem
EasyAtlassian logoAtlassianFULLTIMEOA

Problem statement

Process put, get, and remove operations without using a built-in hash-table implementation for the stored map. Get returns the value or -1 when absent. Return "null" for put and remove operations.

Function

runHashMap(operations: String[], keys: int[], values: int[]) → String[]

Examples

Example 1

operations = ["put","put","get","get","put","get","remove","get"]keys = [1,2,1,3,2,2,2,2]values = [1,2,0,0,1,0,0,0]return = ["null","null","1","-1","null","1","null","-1"]

The second put updates key 2, and remove makes its later get return -1.

Constraints

  • All arrays have equal non-zero length.
  • 0 <= key <= 1000000
  • 0 <= value <= 1000000
  • There are at most 100000 operations.

More Atlassian problems

drafts saved locally
public String[] runHashMap(String[] operations, int[] keys, int[] values) {
  // Write your code here.
}
operations["put","put","get","get","put","get","remove","get"]
keys[1,2,1,3,2,2,2,2]
values[1,2,0,0,1,0,0,0]
expected["null", "null", "1", "-1", "null", "1", "null", "-1"]
checking account