Data structure: insert, remove, contains, get random element, all at O(1)

后端 未结 14 725
别跟我提以往
别跟我提以往 2020-11-29 14:53

I was given this problem in an interview. How would you have answered?

Design a data structure that offers the following operations in O(1) time:

  • inse
14条回答
  •  佛祖请我去吃肉
    2020-11-29 15:15

    Why don't we use epoch%arraysize to find random element. Finding array size is O(n) but amortized complexity will be O(1).

提交回复
热议问题