895. Maximum Frequency Stack
Practice Maximum Frequency Stack for free on NudgeCode: Hard, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a stack-like structure where pop removes the most frequent value.
push(val)pushesvalpop()removes and returns the value that currently appears most often; if several values tie, remove the one pushed most recently among them
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["FreqStack","push","push","push","push","pop","pop"]
[[],[4],[7],[4],[7],[],[]]
-> [null,null,null,null,null,7,4]
Constraints
- 0 <= val <= 10^9
popis only called on a non-empty stack- at most 2 * 10^4 calls