Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top K Frequent Security Events

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

Your question is Top K Frequent Security Events. 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

Given a list of log lines logs, where each line is a string in the format "timestamp source severity event_id message", and an integer k, return the k most frequent event_id values among lines whose severity is at least min_severity. Severity order is DEBUG < INFO < WARN < ERROR < CRITICAL. If two event IDs have the same frequency, return the lexicographically smaller one first. Ignore malformed lines.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= k <= 10^4
  • Each valid log line contains at least 5 space-separated fields
  • min_severity is one of DEBUG, INFO, WARN, ERROR, CRITICAL

Function Signature

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