My first instinct was to just loop through every title and do a string search, which works but they clearly wanted something smarter.
Start by clarifying requirements and edge cases, then outline a solution that normalizes text by removing punctuation and lowercasing, and uses word-boundary matching (e.g., regex with \b) to find the keyword as a complete word. Discuss efficiency for large lists and potential system design considerations like indexing or caching.
Pro tip: Mention that in production, you'd likely preprocess titles into a normalized token set or use a search index (e.g., Elasticsearch) to avoid O(n) scans per query, showing awareness of scalability beyond the basic algorithm.
Ask about punctuation handling (e.g., hyphens, apostrophes), case sensitivity, and whether the keyword can contain punctuation. Confirm expected input sizes and performance needs.
Decide how to strip punctuation and lowercase both titles and keyword. Consider using Unicode-aware regex or a tokenization approach to handle special characters correctly.
Use word-boundary regex (e.g., \bkeyword\b) or split titles into tokens and check for exact token match. Ensure the keyword is treated as a complete word, not a substring.
Discuss time complexity (O(n*m) for naive scan) and propose optimizations like precomputing normalized tokens or using an inverted index for large-scale systems.
Walk through test cases: keyword with punctuation, case variations, partial matches (should not match), and empty inputs. Mention unit testing and edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.