Your question is Top K Vehicle IDs in Logs. 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.
Cox Automotive processes vehicle telemetry logs that may be too large to load into memory at once. Given an iterable of log lines and an integer k, return the vehicle IDs that report most frequently.
Each line uses the format timestamp,vehicle_id,event, and the vehicle ID is the second comma-separated field. Return exactly k IDs when at least k distinct vehicles exist. Rank vehicles by descending report count, then lexicographically ascending vehicle ID to make ties deterministic.
Your function must process the input as an iterable, such as a file iterator, rather than requiring the entire log to be stored in a list. Use an algorithm that avoids sorting every distinct vehicle when k is much smaller than the number of vehicles.
log_lines, an iterable of strings, and k, a positive integer.def top_k_vehicle_ids(log_lines, k):