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
ExperiencesCoaching
New
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
Get started
Log Parsing for Outage Patterns
00:00
5 left

Log Parsing for Outage Patterns

MediumPython

Problem

Write a script or function to parse a log file and identify patterns indicating a service outage.

Implement identify_outages(log_lines, threshold). Each line has the format timestamp|level|message. A line indicates an outage condition when its level is ERROR or CRITICAL. Return consecutive outage intervals containing at least threshold qualifying lines. Each result must contain the first timestamp, last timestamp, and number of qualifying lines. Ignore unrelated lines and malformed lines.

Input and Output

log_lines is a list of strings, and threshold is a positive integer. Return a list of dictionaries with keys start, end, and count, in chronological input order.

Constraints

  • 1 <= len(log_lines) <= 1000
  • 1 <= threshold <= len(log_lines)
  • Each valid line has the format timestamp|level|message
  • A timestamp and message contain no pipe character
  • Only ERROR and CRITICAL levels indicate outage conditions
  • Malformed lines must be ignored and terminate the current run

Function Signature

def identify_outages(log_lines, threshold):
Interviewer

Your question is Log Parsing for Outage Patterns. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.