All problems
Hash Set Operations
Problem
Simulate a hash set supporting add, remove, and contains.
operations contains "add", "remove", or "contains"; values provides the key. add records None, remove records True when the key was present and False otherwise, and contains records a boolean.
Return the list of recorded results.
Hint
Python's built-in set is fine: add, discard, and the in operator are all O(1) average.
Test cases
case 1
in: [["add","add","contains","remove","contains"],[1,2,2,2,2]]
expected: [null,null,true,true,false]
case 2
in: [["remove","add","contains"],[5,5,5]]
expected: [false,null,true]
case 3
in: [["add","add","add","contains","contains"],[1,1,2,1,2]]
expected: [null,null,null,true,true]
case 4
in: [["contains"],[7]]
expected: [false]
Starter codePython
def hash_set_ops(operations, values):
# Your code here
pass4 test cases · run your code against them in the editor