Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
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

Your question is Return Only Matching Book Title. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.