← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Maximum Frequency Stack is LeetCode problem 895, commonly asked in Amazon interviews with tags Hash Table, Stack, and Design. It requires implementing a FreqStack class that prioritizes popping the most frequent element, with ties broken by recency (closest to top).[1][7]
Design a stack-like data structure called FreqStack with these operations:
FreqStack(): Initializes an empty stack.void push(int val): Pushes integer val onto the top.int pop(): Removes and returns the most frequent element. If multiple elements share the maximum frequency, return the one closest to the top.[3][7][1]When popping:
pop().[1][3]` Input: ["FreqStack", "push", "push", "push", "push", "push", "push", "pop", "pop", "pop", "pop"] [[], [5], [7], [5], [7], [4], [5], [], [], [], []]
Output: [null, null, null, null, null, null, null, 5, 7, 5, 4]
Explanation:
0 <= val <= 10^9push and pop()pop().[7][3]