Your question is Find Top-K Frequent Interactions. 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.
Pearson MyLab collects student engagement logs, where each log identifies an interaction such as "view_assignment" or "submit_quiz". Given a list of interaction names and an integer k, return the k most frequent interactions.
Use frequency counting and an efficient selection strategy rather than sorting every interaction when k is much smaller than the number of distinct interactions.
Implement top_k_interactions(logs, k).
logs, a list of strings, and k, a positive integer.[interaction, frequency] pairs.k exceeds the number of distinct interactions.def top_k_interactions(logs, k):