Design HashMap
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement a key-value map, MyHashMap, **without** using any built-in hash table (no dict, set, or similar library container for the mapping itself).
- MyHashMap() creates an empty map.
- put(key, value) stores value under key, overwriting any existing value for that key.
- get(key) returns the value stored under key, or -1 if the key is not present.
- remove(key) deletes key and its value if present; otherwise it does nothing.
Keys and values are non-negative integers. Operations should run in expected O(1) time for a reasonable number of stored keys.
Examples
Constraints
- 0 <= key, value <= 10^6
- At most 10^4 calls are made to `put`, `get` and `remove`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.