Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Top-K most active accounts

Python data engineering interview problem. Difficulty: intermediate. Pattern: Sorting. About 15 minutes. Part of the Pro drill bank.

An activity feed lists account ids. Support wants the k accounts that appear most often so they can investigate noisy customers first.

Return the top-k most frequent accounts.

Requirements

  • Frequency is the sort key.
  • Ties should follow a deterministic rule.

Constraints

  • events: account ids.
  • k: how many accounts to keep.
  • k may be larger than the number of distinct accounts.

Examples

Input: top_k_accounts(['a', 'b', 'a', 'c', 'b', 'a'], 2) Output: ['a', 'b'] This input follows the stated rules and produces this output.

Topics: lakebench, python, sorting.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Top-K most active accounts

Interview-style drill: Given a list of account activity events, return the K accounts with the most events.

Return the top-k most frequent accounts.