Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Return Only Matching Book Title
00:00
5 left

Return Only Matching Book Title

MediumPython

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):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.