Maximum Frequency Stack
A hard-tier problem at 66% community acceptance, tagged with Hash Table, Stack, Design. Reported in interviews at Salesforce and 4 others.
You're building a data structure that tracks the most frequently used element, then returns it in insertion order. Salesforce, Uber, PayPal, and Snap have all asked this. It's a hard problem that feels impossible until you see the pattern: frequency is the primary sort key, not value. Most candidates try to use a single max heap and get stuck when ties break the wrong way. If you hit this in a live assessment and your initial approach collapses, StealthCoder surfaces the frequency-bucketing solution in seconds, invisible to the proctor.
Companies that ask "Maximum Frequency Stack"
Maximum Frequency Stack is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is decoupling frequency tracking from the retrieval mechanism. You need three data structures working together: a hash map for element counts, a hash map mapping frequency to a stack of elements (ordered by insertion), and a max frequency counter. When you push an element, increment its count, pop it from its old frequency bucket, and push it onto the new one. When you pop, return from the max frequency bucket. The catch most miss: you can't just decrement max frequency blindly. You need to track it explicitly and only drop it when that bucket empties. The naive heap approach fails because standard heaps don't let you efficiently reorder on tie-break. StealthCoder is your fallback if you blank on the three-map architecture during the live OA.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Frequency Stack recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Frequency Stack interview FAQ
Is this still asked at FAANG companies?+
Yes. Salesforce, Uber, PayPal, and Snap have all reported asking it. It's a hard-rated problem, so expect it more in senior or backend loops. The 66% acceptance rate suggests candidates who've seen the pattern solve it cleanly, but cold solves stall on the data structure design.
What's the actual trick I'm missing if my solution times out?+
You're probably using a heap and trying to update elements in-place, which is O(n log n) per operation. The solution uses three maps and bucketing by frequency, making every operation O(1). The frequency stack handles insertion order automatically, eliminating the need to reorder on tie-break.
Does this relate to LRU Cache, or is it totally different?+
Related but distinct. LRU uses recency; this uses frequency. Both need O(1) ops and custom tie-breaking. LRU uses a doubly-linked list and hash map. This uses frequency buckets and stacks. If you've nailed LRU, the design pattern translates, but the bucketing logic is new.
How much time should I allocate if I see this live?+
If you know the pattern, 20-30 minutes to code cleanly. If you're cold, expect 45+ minutes of whiteboarding the three-map logic, testing tie-breaks, and debugging insertion order. This is why prep matters. If you blank, that's where the safety net kicks in.
What's the most common mistake in the implementation?+
Not tracking max frequency explicitly and failing to decrement it when a bucket empties. Or using a regular heap instead of frequency stacks, which breaks insertion-order tie-breaking. Test with two elements of equal frequency inserted in different order and you'll catch it.
Want the actual problem statement? View "Maximum Frequency Stack" on LeetCode →