Tweet Counts Per Frequency
A medium-tier problem at 45% community acceptance, tagged with Hash Table, Binary Search, Design. Reported in interviews at X and 0 others.
You're asked to design a system that tracks tweet counts and retrieves them by frequency. X has asked this problem. It's a medium-difficulty design problem with a 45% acceptance rate, so most candidates fail their first attempt. You need to handle two operations efficiently: recording a tweet count and querying all tweets at a given frequency. The trap is thinking a simple hash table is enough. It's not. You'll need to combine hash tables with a structure that keeps frequencies sorted and tied tweets ordered. If you blank during the live assessment, StealthCoder surfaces a working solution invisibly.
Companies that ask "Tweet Counts Per Frequency"
Tweet Counts Per Frequency 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe core trick is layering data structures. A naive approach uses a hash map to store tweet ID to count, but querying by frequency becomes slow. The real solution uses three structures working together: one hash map from tweet ID to current count, another from frequency to the set of tweets at that frequency, and a third tracking the maximum frequency seen. When a tweet gets counted again, you decrement its old frequency bucket, increment the new one, and update max frequency. The gotcha is handling the ordered set of tweets at each frequency efficiently. Many candidates reach for a plain list and time out on sort. You need an actual ordered container like a tree set or equivalent. This is where design knowledge separates solvers from blankers. StealthCoder is your hedge if you didn't practice the specific ordered-set library syntax.
Pattern tags
You know the problem.
Make sure you actually pass it.
Tweet Counts Per Frequency recycles across companies for a reason. It's medium-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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Tweet Counts Per Frequency interview FAQ
Is this really asked at major tech companies?+
Yes. X has confirmed asking it. The 45% acceptance rate means it's selective but not impossible. Most failures come from incomplete data structure choices, not algorithmic misunderstanding. Design problems often have lower pass rates because many candidates skip the step of choosing the right container types upfront.
What makes this hard?+
The problem itself is straightforward until you optimize. A naive solution works for small inputs but times out on large ones. You need to understand when hash tables alone fail and why you need an ordered set. That connection isn't obvious unless you've seen frequency-based design problems before.
Do I need advanced data structures?+
Not advanced, but specific. You need hash tables, an ordered set or tree map, and the ability to manage multiple data structures in sync. Most languages have built-in ordered sets or tree structures. Know your language's standard library cold before the OA.
How does this relate to hash tables and sorting?+
Hash tables get you O(1) lookups, but you can't query by frequency efficiently with just a hash table. Sorting helps conceptually, but sorting the entire frequency map on every query is too slow. The solution uses an ordered set at each frequency level to avoid full sorts.
What's the most common mistake?+
Using a plain list or array to store tweets at each frequency, then sorting on query. That's O(n log n) per query. The correct move is maintaining an ordered set per frequency, so tweets stay sorted as you insert and remove. This keeps operations O(log n).
Want the actual problem statement? View "Tweet Counts Per Frequency" on LeetCode →