Top K Most Frequent Senders in a Yahoo Mail Inbox
Last updated: November 29, 2026
Quick Overview
Given a list of sender addresses for every message in an inbox and an integer k, return the k senders with the most messages and their counts, highest first, breaking ties alphabetically. Addresses compare case-insensitively.
Yahoo
November 29, 20260
0
0 solved
Given a list of sender addresses for every message in an inbox and an integer k, return the k senders with the most messages and their counts, highest first, breaking ties alphabetically. Addresses compare case-insensitively.
This kind of warm-up shows up in Yahoo phone screens and maps to inbox features like sender-based cleanup and 'unsubscribe from frequent senders'. The interviewer wants a correct counting solution, a sensible heap choice, and deterministic tie-breaking.
What the Interviewer Expects
- Count with a hash map after normalizing case and whitespace
- Select top k with a heap rather than a full sort when k is small
- Make the tie-break explicit and deterministic
- Give O(n + u log k) time where u is unique senders
- Handle k larger than the number of senders
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you compute this across 200 million inboxes for a weekly report?
- How would you approximate top senders in a stream with limited memory?
- How would you group '[email protected]' and '[email protected]' as one sender domain?
- When would bucket sort beat a heap here?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: messages (list of sender strings), k. Output: up to k (sender, count) pairs, count descending, sender ascending on ties. A@x and a@x are the same sender....
High-Level Design
- Normalize and count with
Counter: O(n). - Select the k best of u unique senders.
heapq.nsmallestwith key(-count, sender)keeps a heap of size k internally, which is O(u log k) and returns ...