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
Coding & Algorithms
Software Engineer
eBay
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
recursive descent parsing
operator precedence
inverted index
set operations
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
  • 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 Problems
Sample 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...

Submit Your Answer
Markdown supported