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).