Interview questions · Enigma
Search Book Titles
This question evaluates proficiency in string processing, tokenization, case-insensitive matching, anagram detection, and algorithmic design for efficient search and deduplication.
You are given a list of book titles and a user query string. Return all titles that are relevant to the query.
A title is considered relevant if any token in the title matches the query under at least one of these rules:
- Exact match: the token equals the query, ignoring case.
- Autocomplete match: the token starts with the query, ignoring case.
- Reordered-letter match: the token is an anagram of the query, ignoring case. For example,
culbmatchesClubbecause they contain the same letters.
Requirements:
- Tokenize each title into words by splitting on spaces.
- Matching is case-insensitive.
- Return each matching title at most once.
- Preserve the original input order of titles.
Example:
- Titles:
["The Luck of Club"] - Query:
"Luck"-> return["The Luck of Club"] - Query:
"luc"-> return["The Luck of Club"]becauselucis a prefix ofLuck - Query:
"culb"-> return["The Luck of Club"]becauseculbis an anagram ofClub
Design and implement an efficient function for this search problem. Discuss the trade-offs between preprocessing the titles and answering queries quickly.
Community answers
Nothing here yet.
Join in on CSWork →