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

0

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
hash maps
string normalization
regular expressions
sorting
email threading
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 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 Problems
Sample 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
  1. Normalize each subject with a regex anchored at the start that repeatedly consumes prefixes.
  2. Bucket (timestamp, id) pairs in a dict keyed by the normalized subject.
  3. Sort each bucket, record...

Submit Your Answer
Markdown supported

Related Questions