Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Stream Large Log Files

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

Your question is Stream Large Log Files. 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 lines, where each line is a JSON object with string fields "user" and "event", return a dictionary mapping each user to the number of distinct event types seen for that user. Invalid JSON lines or lines missing either field should be ignored. The solution should process the input in a memory-efficient way and avoid storing parsed records unnecessarily.

Constraints

  • 1 <= len(lines) <= 10^5
  • Each line length is at most 10^4
  • user and event values, when present, are non-empty strings
  • Invalid JSON lines may appear anywhere in the input

Function Signature

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