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
Coding & Algorithms
Software Engineer
Yahoo
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
hash maps
heaps
top-k
sorting
normalization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. Normalize and count with Counter: O(n).
  2. Select the k best of u unique senders. heapq.nsmallest with key (-count, sender) keeps a heap of size k internally, which is O(u log k) and returns ...

Submit Your Answer
Markdown supported