Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Efficient Log Parsing Script
00:00
5 left

Efficient Log Parsing Script

HardPython

Problem

Citadel's observability pipeline receives log data that may be too large to load into memory. Given an iterable of log lines and a collection of error patterns, count every occurrence of each pattern in one streaming pass.

Matches may overlap, and a pattern cannot span two log lines. For example, "AAAA" contains three occurrences of "AA". Return a dictionary containing every requested pattern, including patterns with zero matches.

Formal Specification

Implement count_error_patterns(lines, patterns).

  • lines is an iterable of strings. It may be a generator, so do not assume it can be indexed or reread.
  • patterns is a list of distinct, non-empty strings.
  • Return a dictionary mapping each pattern to its total number of occurrences across all lines.
  • Matching is case-sensitive and counts overlapping occurrences.

Use an algorithm that avoids scanning every pattern independently for every line.

Constraints

  • 1 <= len(patterns) <= 10^4
  • The total number of characters in all patterns is at most 2 * 10^5
  • The total number of characters across all input lines is at most 10^7
  • Every pattern is non-empty and patterns are distinct
  • Input lines and patterns contain printable ASCII characters

Function Signature

def count_error_patterns(lines, patterns):
Interviewer

Your question is Efficient Log Parsing Script. 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.