Step 1 of 4

Bucket Storage & Basic Hashing

Start by implementing set(key, value) and get(key) over the initial bucket array.

The hash(key) method is provided to convert keys to a valid bucket index ($0 \le \text{index} < \text{capacity}$).

  • set(key, value): Place the [key, value] pair into the appropriate bucket. If the key already exists in that bucket, update its value.
  • get(key): Retrieve the value stored under key, or return null / None if not found.

Your build

Running is free — Submit is what records the step. Or press ⌘↩

Tests

2 cases
calltypeexpectedresult
runOps(8, [["set","apple",10],["set","banana",20],["get","apple"],["get","banana"],["get","cherry"]])sets and gets unique keys[null,null,10,20,null]
runOps(8, [["set","user_1","Alice"],["get","user_1"],["set","user_1","Alicia"],["get","user_1"]])updates existing key value[null,"Alice",null,"Alicia"]

Hints

Stuck? Hints open one at a time, each giving a little more away.

3 hints left