Parse Yahoo Mail Search Operators Into Structured Filters
Last updated: November 29, 2026
Quick Overview
Write a parser for a mail search box that turns a string like from:alice has:attachment "quarterly report" -spam subject:"Q3 plan" into structured filters, free-text terms, and excluded terms. Quoted values may contain spaces.
Yahoo
November 29, 20260
0
0 solved
Write a parser for a mail search box that turns a string like from:alice has:attachment "quarterly report" -spam subject:"Q3 plan" into structured filters, free-text terms, and excluded terms. Quoted values may contain spaces.
Yahoo Mail supports search operators like from:, to:, and has:attachment, and the backend needs a clean structured query. The interviewer is testing careful single-pass string scanning and how you define behavior for malformed input.
What the Interviewer Expects
- Scan character by character instead of naive split on spaces
- Support key:value, key:"quoted value", and bare quoted phrases
- Handle a leading '-' as negation
- Define behavior for unterminated quotes and empty values
- Keep it O(n) and easy to extend with new operators
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 add OR and parentheses grouping?
- How would you validate operator names and values like dates in before:2024-01-01?
- How would you translate the result into a search engine query?
- How should the parser behave with full-width quotes from mobile keyboards?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Output a dict with filters (operator to list of values, negated operators prefixed with -), terms (free text, quoted phrases kept whole), and excluded (negated free text). Operator names are l...
High-Level Design
A single left-to-right scan builds one token at a time:
- Skip whitespace between tokens.
- A
-followed by a non-space marks negation. - Inside a token, a
"consumes everything up to the next quo...