Sort employee records

tuples

Sort employee records

Workday Python Interview Question

Workday exports employee records as (name, department, salary) entries. HR wants them sorted by department from A to Z, then by salary from highest to lowest, then by name from A to Z.

Write a function sort_employees(records) that takes a list of [name, department, salary] records and returns the names in that order.

Asked of

  • Data Analyst
  • Data Engineer
  • Data Scientist
  • ML Engineer
  • AI Engineer

Example 1

Input

records = [["Leo", "Data", 120000], ["Ben", "Sales", 90000], ["Priya", "Data", 150000], ["Ana", "Sales", 90000]]

Output

["Priya", "Leo", "Ana", "Ben"]

Example 2

Input

records = [["Zoe", "Ops", 50000]]

Output

["Zoe"]

Explanation

In the first example, the Data department comes before Sales. Inside Data, Priya earns more than Leo, so she comes first. In Sales, Ana and Ben earn the same, so they are ordered by name.

Submit also runs 2 hidden test cases that check edge cases.