The Best-Funded Teams, Ranked
You're on the finance team at Bright Harbor, a software company with four departments. Next year's budgets are being drawn up, and the CFO has asked something the current reports cannot answer: which departments are funded most generously per person, and how many dollars per person is that? A big budget means nothing on its own — it only becomes a number you can compare once you read it against the size of the team it has to cover, and the CFO wants those figures in front of her, not just the names, because the names alone are close to what a straight look at the budget column would also have given her.
How many lines fit on the slide changes from meeting to meeting, so the length of the shortlist comes with the request. Ask for more departments than the company has and the answer is simply all of them, best-funded first.
The awkward part is that team size is written down nowhere. A budget is recorded once, against the department. People are recorded one row each, and they join and leave constantly, so how big a team is depends entirely on what the employee table says today.
departments_df — one row per department. budget is the annual budget in dollars.
| name | budget |
|---|---|
| Engineering | 900000 |
| Sales | 400000 |
| Marketing | 250000 |
| Data | 500000 |
employees_df — one row per current employee. department matches a department's name. salary is annual, and manager is blank for people who report to nobody.
| id | name | department | salary | hire_date | manager |
|---|---|---|---|---|---|
| 1 | Ava Chen | Engineering | 145000 | 2021-03-14 | — |
| 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 | — |
| 5 | Elin Kask | Sales | 88000 | 2022-11-05 | Deshawn Lee |
| 6 | Farid Amiri | Marketing | 76000 | 2023-04-18 | — |
| 7 | Grace Kim | Data | 132000 | 2021-07-30 | — |
| 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
All the tables above are already built for you — the department and employee rows are not read from input. What does arrive is a single line holding how many departments the shortlist should hold, as a whole number.
Task: Print a Python dict mapping department name to budget per employee — that department's budget shared equally between everyone currently in it, rounded to 2 decimals — holding only the most generously funded departments, largest figure first. It holds as many entries as were asked for, or one for every department with staff if fewer than that exist.
Example: if Facilities were the most generously funded per head and a shortlist of one was asked for, the output would look like {'Facilities': 12500.0}.
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