Databricks L4 phone screening question
Anonymous User
1340

Design a set in which we can add and remove element and we will be able to iterate over the elements. when we start iteration on set then current state of set will be iterated. Operations in between iteration will be reflected instatantly in set but will be seen in next iteration.
e.g.

add -> 2
add -> 3
add -> 4
remove -> 3

iteration -> started

add -> 5
contains(5) -> true
remove -> 5
add -> 6
remove -> 6
add -> 6
contains (5) -> false
iteration result -> [2, 4]

interface customSet {
void add(T e);
void remove(T e);
boolean contains(T e);
Iterator getIterator();
}

Comments (3)