Group Yahoo Mail Messages Into Threads by Normalized Subject
Last updated: November 29, 2026
Quick Overview
Given a list of messages as (id, subject, timestamp), group them into conversation threads by subject after stripping reply and forward prefixes such as 'Re:', 'Fwd:', and 'RE[2]:' and normalizing case and whitespace. Return each thread's message ids in time order, with threads sorted by their most recent message.
Yahoo
November 29, 20260
0
0 solved
Given a list of messages as (id, subject, timestamp), group them into conversation threads by subject after stripping reply and forward prefixes such as 'Re:', 'Fwd:', and 'RE[2]:' and normalizing case and whitespace. Return each thread's message ids in time order, with threads sorted by their most recent message.
A warm-up in the style of a Yahoo Mail team phone screen, where conversation view is a core product feature. The interviewer checks that you can pick the right grouping key, write clean hashing code quickly, and think about messy real-world subject lines.
What the Interviewer Expects
- Define a normalization function that strips repeated prefixes like 'Re: Fwd: RE[3]:'
- Group with a hash map keyed by the normalized subject
- Sort messages within a thread by timestamp and threads by latest activity
- State O(n log n) time and O(n) space
- Call out edge cases like empty subjects and localized prefixes such as 'AW:'
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 avoid merging two unrelated threads that both have the subject 'Hello'?
- How would you use In-Reply-To and References headers instead of subjects?
- How would you handle prefixes in other languages, like 'SV:' or 'Antw:'?
- How would this change if messages arrive as a stream?
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: a list of (msg_id, subject, timestamp). Two messages belong to the same thread when their subjects match after removing any stack of reply or forward prefixes (Re:, Fwd:, Fw:, AW:, op...
High-Level Design
- Normalize each subject with a regex anchored at the start that repeatedly consumes prefixes.
- Bucket
(timestamp, id)pairs in a dict keyed by the normalized subject. - Sort each bucket, record...