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.
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.
def count_distinct_events_by_user(lines):