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
Efficient Log Parsing and Validation
00:00
5 left

Efficient Log Parsing and Validation

HardPython

Problem

Splunk ingestion pipelines must parse high-volume event lines while rejecting malformed records without stopping the batch. Each line contains space-separated key=value fields, where values may be quoted and may contain escaped quotes or backslashes.

Implement parse_logs(lines) to parse and validate every line. Return a dictionary with events, a list of valid parsed events, and invalid, the number of rejected lines.

A valid line must contain exactly these fields, with no duplicates or unknown keys:

  • ts: a decimal Unix timestamp from 0 through 2147483647
  • level: one of INFO, WARN, or ERROR
  • service: one or more letters, digits, underscores, or hyphens
  • request_id: exactly 16 hexadecimal characters
  • msg: a quoted string; it may contain spaces, escaped quotes (\\"), and escaped backslashes (\\\\)

Decode valid quoted values before returning them. Store ts as an integer. Preserve the other fields as strings. Lines may have leading or trailing whitespace.

Constraints

  • 1 <= len(lines) <= 10^5
  • Each line contains at most 10^4 characters
  • The total input size is at most 10^6 characters
  • A valid line contains exactly five distinct fields
  • ts is an integer from 0 through 2147483647
  • request_id contains exactly 16 hexadecimal characters

Function Signature

def parse_logs(lines):
Interviewer

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