Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-292

OR-Set Add/Remove Check

Problem

Simulate an observed-remove set (OR-Set).

operations contains "add" (each add attaches a fresh unique tag and records None), "remove" (record None and drop all tags observed for the value), "contains" (record a boolean), or "to_list" (record the sorted values with at least one live tag).

Return the list of recorded results.

Hint

A re-add after remove creates a brand new tag, so the value becomes visible again.

Test cases

case 1
in: [["add","add","remove","contains","add","contains"],[1,2,1,1,1,1]]
expected: [null,null,null,false,null,true]
case 2
in: [["contains"],[9]]
expected: [false]
case 3
in: [["add","add","add","to_list"],[2,1,2,0]]
expected: [null,null,null,[1,2]]
case 4
in: [["add","remove","to_list","add","to_list"],[5,5,0,5,0]]
expected: [null,null,[],null,[5]]
Starter codePython
def orset_ops(operations, values):
    # Your code here
    pass

4 test cases · run your code against them in the editor