This question evaluates the ability to aggregate frequencies and compute top-N results from logs, covering competencies in frequency counting, top-k algorithms, and streaming data handling within the Coding & Algorithms domain at a practical application level.
You are given application logs containing events with an itemId. Each log line may contain extra fields, but you can extract the itemId from each line.
Parse the logs, count how many times each itemId appears, then output the top N most frequent items.
logs
: a list of strings, each representing one log line.
N
: an integer.
item=<id>
or the first whitespace-separated field).
Return a list of the top N itemIds with their counts, sorted by:
1 <= len(logs) <= 10^6
1 <= N <= number of distinct itemIds