Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Articles Containing a Word

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

Your question is Find Articles Containing a Word. 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's content search needs to identify which articles contain a requested word. Given a list of article bodies and one search query, return the indices of every article containing that word as a complete, case-insensitive token.

A word consists of one or more ASCII letters or digits. Punctuation separates words, so ads matches Ads, but does not match adserver. Return article indices in their original order, with no duplicates.

Formal Specification

Implement find_articles(articles, query).

  • articles is a list of strings, where each string is one article's body.
  • query is a non-empty string containing only ASCII letters and digits.
  • Return a list of integers containing the zero-based indices of matching articles.

Constraints

  • 1 <= len(articles) <= 10^4
  • Each article contains at most 10^5 characters
  • Combined article length is at most 10^6 characters
  • The query contains only ASCII letters and digits
  • Matching is case-insensitive and punctuation separates words

Function Signature

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