Maximum Frequency Stack (LC #895) pops the most frequent element. If tied, pop the one closest to the top. Use a frequency map and a map from frequency to stack of elements at that frequency. Track the current max frequency. On push, increment frequency, add to the appropriate stack, update max. On pop, pop from the max frequency stack, decrement that element's frequency, decrement max if the stack becomes empty. All operations are . This is a hard design problem Meta asks for senior roles.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/stacks-queues/maximum-frequency-stack
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████