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