Design a stack-like data structure that pushes elements and pops the most frequent element. If there is a tie for the most frequent element, the element closest to the top of the stack is popped.
Implement the following operations:
push(val)- pushes an integervalonto the stack.pop()- removes and returns the most frequent element in the stack. If there is a tie, the element closest to the stack top is removed.
Input format: An array of commands where each command is either ["push", val] or ["pop"]. Return an array of results where push produces null and pop produces the popped value.