Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Custom sort by multiple derived keys

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

HR exports employee rows that must sort by several derived keys (department, then seniority band, then name) rather than by a single column.

Sort employees by the multiple derived keys described in the prompt.

Requirements

  • Apply keys in the stated priority.
  • Derived keys are computed from the row, not stored.

Constraints

  • rows: employee records.

Examples

Input: sort_employees([{'name': 'b', 'dept': 'eng', 'tenure': 2}, {'name': 'a', 'dept': 'eng', 'tenure': 2}, {'name': 'c', 'dept': 'ops', 'tenure': 9}]) Output: [{'name': 'a', 'dept': 'eng', 'tenure': 2}, {'name': 'b', 'dept': 'eng', 'tenure': 2}, {'name': 'c', 'dept': 'ops', 'tenure': 9}] 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

Custom sort by multiple derived keys

Interview-style drill: Sort a list of employee records by department, then descending tenure, then name.

Sort employees by the multiple derived keys described in the prompt.