Search Book Titles

Quick Overview

This question evaluates proficiency in string processing, tokenization, case-insensitive matching, anagram detection, and algorithmic design for efficient search and deduplication.

Search Book Titles

Company: Enigma

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

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: 1. **Exact match**: the token equals the query, ignoring case. 2. **Autocomplete match**: the token starts with the query, ignoring case. 3. **Reordered-letter match**: the token is an anagram of the query, ignoring case. For example, `culb` matches `Club` because 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"]` because `luc` is a prefix of `Luck` - Query: `"culb"` -> return `["The Luck of Club"]` because `culb` is an anagram of `Club` Design and implement an efficient function for this search problem. Discuss the trade-offs between preprocessing the titles and answering queries quickly.

Overview: This question evaluates proficiency in string processing, tokenization, case-insensitive matching, anagram detection, and algorithmic design for efficient search and deduplication.

|Home/Coding & Algorithms/Enigma
Enigma logo
Enigma
Feb 3, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
4
0

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:

  1. Exact match : the token equals the query, ignoring case.
  2. Autocomplete match : the token starts with the query, ignoring case.
  3. Reordered-letter match : the token is an anagram of the query, ignoring case. For example, culb matches Club because 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"] because luc is a prefix of Luck
  • Query: "culb" -> return ["The Luck of Club"] because culb is an anagram of Club

Design and implement an efficient function for this search problem. Discuss the trade-offs between preprocessing the titles and answering queries quickly.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...