Evaluate Boolean Keyword Queries Against Listing Titles
Last updated: November 29, 2026
Quick Overview
Given listing titles keyed by id and a query using words, AND, OR, NOT and parentheses (adjacent words mean AND), return the sorted ids of listings whose titles satisfy the query, and raise an error for malformed queries.
eBay
November 29, 20260
0
0 solved
Given listing titles keyed by id and a query using words, AND, OR, NOT and parentheses (adjacent words mean AND), return the sorted ids of listings whose titles satisfy the query, and raise an error for malformed queries.
eBay's advanced search lets buyers combine keywords and exclusions, and saved searches replay these queries against new listings. This onsite question checks tokenizing, operator precedence with a recursive descent parser, and set algebra over an inverted index.
What the Interviewer Expects
- Tokenize words, operators and parentheses
- Encode precedence: NOT over AND over OR, with implicit AND
- Write a small recursive descent parser
- Evaluate with set operations on an inverted index
- Report malformed input clearly (dangling operator, unbalanced parens)
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
- Add quoted phrase search such as "iphone 13".
- How would you avoid materializing NOT as a huge set over billions of listings?
- How would you order AND operands to keep intermediate results small?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Words match whole lowercase tokens in the title. Precedence from tightest: NOT, then AND (explicit or implied by adjacency), then OR. Parentheses group. Return sorted matching ids. Errors such a...
High-Level Design
Two stages. First build an inverted index word -> set(ids) and a universe of all ids. Then parse with a grammar that mirrors precedence:
expr := term (OR term)*- `term := factor ((AND)? factor...