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
Count Word Occurrences in Text
00:00
5 left

Count Word Occurrences in Text

MediumPython

Problem

Niantic telemetry and content pipelines may deliver text in chunks rather than as one complete string. Given an iterable stream of text chunks and a list of requested words, count how many times each requested word appears.

Matching is case-insensitive. A word is a contiguous sequence of ASCII letters, and any non-letter character separates words. A requested word is guaranteed to contain only ASCII letters. Do not concatenate the entire stream before processing it, and correctly handle a word split across two chunks.

Formal Specification

Implement count_stream_words(chunks, words), where chunks is an iterable of strings and words is a list of requested words. Return a dictionary mapping each requested word, normalized to lowercase, to its occurrence count. Include every requested word in the result, even when its count is zero. If the input list contains the same word more than once, return one key for that word.

Constraints

  • 1 <= len(words) <= 10^4
  • 1 <= len(word) <= 50 for every requested word
  • The total streamed text length is at most 10^7 characters
  • Chunks may be empty or split words at arbitrary positions
  • Only ASCII letters are part of a word

Function Signature

def count_stream_words(chunks, words):
Interviewer

Your question is Count Word Occurrences in Text. 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.