Best in Class
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L5
Problem
A scoring pipeline emits records as it runs, each a dict carrying a `category` label and a numeric `value`, and downstream only wants a per-category shortlist. For every category that appears, return its `n` highest-`value` records keyed by that category, passing the original dicts through untouched. When records in a category share a value, the one that appeared earlier in `records` comes first; a category with fewer than `n` records contributes all it has, and empty input yields an empty dict.
Summary
Every category keeps its leaders. The rest fall away.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.