Design HashSet
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 set of integers, MyHashSet, **without** using any built-in hash table or set library.
- MyHashSet() creates an empty set.
- add(key) inserts key; adding a key that is already present has no effect.
- remove(key) deletes key if present; otherwise it does nothing.
- contains(key) returns true if key is in the set, otherwise false.
Operations should run in expected O(1) time for a reasonable number of stored keys.
Examples
Constraints
- 0 <= key <= 10^6
- At most 10^4 calls are made to `add`, `remove` and `contains`.
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.