This is an interview question. I need to implement a data structure that supports the following operations:
Insertion of an integer in $O(1)$
Deletion of an integer (for example, if we call delete(7), then 7 is deleted from the data structure, if the integer 7 exists in it) in $O(1)$.
Return maximum integer in the data structure (without deleting it) in $O(1)$.
You can also use up to $O(n)$ space.
I thought of something similar to this question, but here we have $O(\mathrm{log}\ n)$.
Do you know how can we implement these operations in $O(1)$?
Edit: forgot important thing - you can assume the numbers that will be inserted are integers in the range $[0,n]$.
Retrun
?) (the purpose here
proposition?) Is this to be a set or a multiset / bag (insert7
twice, delete it once: still in)? $\endgroup$