This question was asked in the interview:
Propose and implement a data structure that works with integer data from final and continuous ranges of integers. The data structure should support O(1)
insert and remove operations as well findOldest
(the oldest value inserted to the data structure).
No duplication is allowed (i.e. if some value already inside - it should not be added once more)
Also, if needed, the some init might be used for initialization.
I proposed a solution to use an array (size as range size) of 1/0 indicating the value is inside. It solves insert/remove and requires O(range size)
initialization.
But I have no idea how to implement findOldest
with the given constraints.
Any ideas?
P.S. No dynamic allocation is allowed.