Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Design HashSet

Easy

Topics
ArrayHash TableDesign

Design a HashSet without using any built-in hash set libraries. Implement MyHashSet with add(key), contains(key) (returns whether the key is present), and remove(key).

Example 1

Input:  operations = ["MyHashSet","add","add","contains","contains","add","contains","remove","contains"], values = [[],[1],[2],[1],[3],[2],[2],[2],[2]]
Output: [null,null,null,true,false,null,true,null,false]

Constraints

  • 0 <= key <= 10^6
  • At most 10^4 calls to add, remove, and contains.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access