Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Return Only Matching Book Title

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Return Only Matching Book Title. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

NextRoll stores a large catalog export as newline-delimited book records. Each record contains a title, description, and author separated by |. Given the export and a search word, return the title of the first book whose title, description, or author contains that word as a complete case-insensitive word.

Process records in input order. Return None when no book matches. A word must not match as part of a larger alphanumeric or underscore token. For example, ad does not match advertising.

Formal Specification

Implement find_book_title(books_text, search_word).

  • books_text is a string containing zero or more records separated by newline characters.
  • Each non-empty record has the form title|description|author.
  • Titles, descriptions, and authors do not contain | or newline characters.
  • search_word is a non-empty string without whitespace.
  • Return the matching title as a string, or None if no record matches.

Constraints

  • 1 <= len(books_text) <= 10^7
  • Each non-empty record contains exactly three pipe-separated fields
  • Titles, descriptions, and authors do not contain | or newline characters
  • search_word is non-empty and contains no whitespace
  • Matching is case-insensitive and uses Unicode word-character boundaries
  • Return the first matching title in input order

Function Signature

def find_book_title(books_text, search_word):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output