Your question is Top N From 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.
Given a collection of log entries as input, compute and output the top N items.
Asked in the Phone Interview stage. Coding problem during Generative AI / Java backend AI Engineer phone interview.
Implement a function that takes a list of log entry strings and an integer n, and returns the n most frequent entries. If two entries have the same frequency, return them in lexicographic order.
logs: list of stringsn: integern items in the required orderdef top_n_items(logs, n):