dsa · medium

Maximum Frequency Stack

GreyOrangeHash MapStackDesign

FreqStack: push(val), pop() removes the most frequent remaining value; ties → the closest to the top of the stack.

Fill in the FreqStack class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.

**Example**

`` FreqStack() → null push(5) → null push(7) → null push(5) → null push(7) → null push(4) → null push(5) → null pop() → 5 pop() → 7 pop() → 5 pop() → 4 ``

Constraints

Calls <= 1000

Examples

Example 1

Input:
["FreqStack","push","push","push","push","push","push","pop","pop","pop","pop"]
[[],[5],[7],[5],[7],[4],[5],[],[],[],[]]

Expected:
[null,null,null,null,null,null,null,5,7,5,4]

Open in the Dojo editor