Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Finding Frequent Error Patterns

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

Your question is Finding Frequent Error Patterns. 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

Oracle Health services produce logs containing timestamps, severity levels, error codes, and messages. Given an array of log strings, identify the k most frequent error patterns while grouping messages that differ only by numeric values.

Each log has the format timestamp level error_code message, where the message may contain spaces. Consider only logs whose level is ERROR. A pattern consists of the error code followed by the message after replacing every standalone sequence of decimal digits with <NUM>.

Return a list of [pattern, count] pairs ordered by decreasing frequency. If two patterns have the same frequency, order them lexicographically by their pattern string.

Formal Specification

  • Input: logs, a list of valid strings, and k, a positive integer.
  • Output: A list containing at most k pairs. Each pair contains a normalized pattern string and its occurrence count.

Constraints

  • 1 <= len(logs) <= 10^5
  • Each log contains a timestamp, level, error code, and nonempty message
  • 1 <= k <= 10^5
  • Each message contains at most 10^3 characters
  • Numeric values are standalone decimal digit sequences

Function Signature

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