 All Problems
Design HashMap
easy
design
array
hash table
linked list
amazon
bloomberg

Design a HashMap without using any built-in hash table libraries.

Implement the MyHashMap class:

  • void put(int key, int value) — insert or update.
  • int get(int key) — return value or -1.
  • void remove(int key) — remove key if present.

Example:

put(1,1), put(2,2), get(1)→1, get(3)→-1, put(2,1), get(2)→1, remove(2), get(2)→-1

Constraints: 0 <= key, value <= 10^6

Run to check your code against the sample cases, or submit to run every case