03 · OOP for DSA & Design Rounds

#705 Design HashSet

Easysolve on LeetCode ↗

frequently reported atAmazon

the problem

In plain words

Build a set of integer keys without any built-in hash table. MyHashSet() creates an empty set, add(key) inserts a key (no duplicates), remove(key) deletes it if present, and contains(key) says whether it is there.

in add(1), add(2), contains(1), contains(3), add(2), contains(2), remove(2), contains(2)

out null, null, true, false, null, true, null, false

Adding 2 a second time changes nothing; after remove(2), contains(2) is false.

  • 0 ≤ key ≤ 10⁶
  • At most 10⁴ calls to add, remove and contains

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #217
      Contains Duplicate
      Easyin Hashing
    2. #1
      Two Sum
      Easyin Hashing
    3. #707
      Design Linked List
      Mediumin Java OOP