2dbi

Maximum Frequency Stack

viaLeetCode

Implement a FreqStack that supports push(x) and pop(). pop() removes and returns the most frequent element; if several elements share the maximum frequency, it returns the one pushed most recently. Implement with a hash map of element->frequency and a map of frequency->stack of elements.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account