Loading problem…
Implement a FreqStack class. push(value) adds an occurrence. pop() removes and returns the value with the most occurrences currently present. When values tie, remove the one whose latest remaining occurrence was pushed most recently.
A pop removes only one occurrence, not every copy of that value. Pop is called only when the structure is nonempty. Aim for average O(1) time per operation.
Tests use named operations and values arrays. The first operation constructs FreqStack; constructor and push outputs are null.
Example 1:
Example 2:
Example 3: