Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Frequent Error Sequences

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

Your question is Find Frequent Error Sequences. 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

Astra logs contain timestamped error codes generated by platform components. Given a list of log events and a sequence length k, return the most frequent contiguous sequence of k error codes after ordering events chronologically.

Each event is represented as [timestamp, error_code], where timestamp is a unique integer and error_code is a string. Count overlapping sequences. If multiple sequences have the same highest frequency, return the lexicographically smallest sequence. Return an empty list when fewer than k events are provided.

Formal Specification

Implement most_frequent_error_sequence(logs, k).

  • Input: logs, a list of [int, str] pairs, and positive integer k
  • Output: a list of k error-code strings representing the selected sequence
  • Timestamps may be unsorted in the input, but are unique
  • The input list must not be modified

Constraints

  • 0 <= len(logs) <= 100000
  • 1 <= k <= len(logs) when logs is non-empty
  • Each event has the form [timestamp, error_code]
  • Timestamps are unique integers
  • Error codes are non-empty strings

Function Signature

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