CareerCup Implement a stack that pops out the most frequently added item

来源:互联网 发布:淘宝那些东西增加权重 编辑:程序博客网 时间:2024/04/30 17:04

Implement a stack that pops out the most frequently added item. Stack supports 3 functions - push, pop,and top. Give complexity of each functions in your implementation.

--------------------------------------------------------------

One option is to combine heap (to get top) with hashtable (to find element in heap). That way insert is o(logn) and retrieval is o(1).


0 0