Question

link

Code a hashmap which you would be happy to place into a production environment.

Solution

We already write 2 post before:

  1. [Question] Implement a HashMap

  2. [CC150v5] 8.10 Implement a Hashmap

But still, this is not an easy question when asked at an interview. It won’t harm to do a little recap:

  1. The basic structure is an array. It can be:
    1. An array of linked nodes (with a next pointer).
    2. An array of linked list.
  2. There should be a hash function.
  3. There should be a function to convert the hash value to corresponding array index.
  4. Remember there’s a concept of Load factor. It means to what percentage the hashmap is filled.
  5. h & (length – 1) means h % length, which maps a hashcode to an array index.