Back to DSA sheet

Design HashSet

EasyArrays

Design a hash set without using a built-in set library. Support add(key), remove(key), and contains(key).

Input format (stdin): the first line has q (number of operations). Each next line is one of: 'add x', 'remove x', or 'contains x'. For every contains operation, print true or false on its own line.

Examples
Input: 7 add 1 add 2 contains 1 contains 3 add 2 remove 2 contains 2
Output: true false false
1 is present, 3 is not, and after removing 2 it is gone.
Constraints
  • 0 <= key <= 10^6
  • 1 <= q <= 10^4
Sheets
NeetCode 250
design-hashset.cpp1 sample tests
Loading editor
Test results

Run the sample tests to check your solution against expected output.

Custom input (stdin)
Output

Run your code to see its output.