All problems

Employees Earning Above Department Average

mediumPythonGroupByTransform

You're a data analyst at Kestrel Robotics, and HR is preparing a mid-year pay review. Someone suggested simply flagging everyone paid above the company average. HR killed that idea on the spot: engineers would fill the entire list and nobody in Marketing would ever appear on it, however well they were paid. The comparison only carries meaning inside a department.

So the rule is relative, and it has a dial on it: HR flags anyone paid more than a given percentage clear of their own department's average. The percentage is argued over every cycle and arrives with the request.

Which makes the question fiddly. Each person has to be measured against a number worked out from the very rows they are sitting in — including their own salary, which they are helping to raise.

employees_df — one row per employee. salary is annual, in dollars. manager is None for anyone who reports to nobody in this table.

id name department salary hire_date manager
1 Ava Chen Engineering 145000 2021-03-14 None
2 Ben Ortiz Engineering 118000 2022-06-01 Ava Chen
3 Cara Novak Engineering 121000 2023-01-10 Ava Chen
4 Deshawn Lee Sales 95000 2020-09-23 None
5 Elin Kask Sales 88000 2022-11-05 Deshawn Lee
6 Farid Amiri Marketing 76000 2023-04-18 None
7 Grace Kim Data 132000 2021-07-30 None
8 Hugo Silva Data 110000 2023-02-14 Grace Kim
9 Ines Duarte Data 104000 2023-08-01 Grace Kim
10 Jonas Weber Sales 91000 2021-12-19 Deshawn Lee

Input

The DataFrame above is already built for you — the employee rows are not read from input. What does arrive is a single line holding this cycle's margin, as a percentage: 0 puts the bar on the department average itself, 10 puts it ten percent above the average, and so on.

Task: Print a sorted Python list of the names of employees whose salary is strictly above their own department's bar. The average behind that bar includes the employee being tested. Strictly above means somebody sitting exactly on the bar does not make the list — which is also why nobody in a one-person department can make it at a margin of zero, since their salary is their department's average. If nobody clears the bar, print an empty list.

Example: if two people cleared their own department's bar, you'd print ['Ada Byron', 'Kai Mensah'].

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…