easy +10 pts

Employees earning more than manager

Compare employee salaries with their managers using a dictionary-based relationship graph.

You are given a list of employee records. Each record is a dictionary with keys: 'id' (int), 'name' (str), 'salary' (int), and 'manager_id' (int or None). The 'manager_id' refers to the 'id' of another employee who is their direct manager. An employee with 'manager_id' None has no manager. Implement the function `employees_earning_more_than_manager(employees)` that returns a list of names of employees who earn strictly more than their direct manager. The returned list must be sorted alphabetically. Assumptions: - Employee IDs are unique. - Every 'manager_id' (if not None) refers to an existing employee ID. - Salaries are non-negative integers. - If an employee has no manager, they do not qualify (even if they have the highest salary). Return an empty list if no employee earns more than their manager.

Constraints

1 <= len(employees) <= 1000 Salaries are in range 0 to 10^6. Time complexity: O(n), where n is number of employees. Space complexity: O(n).

Example

>>> employees = [
...     {'id': 1, 'name': 'Alice', 'salary': 8000, 'manager_id': None},
...     {'id': 2, 'name': 'Bob', 'salary': 9000, 'manager_id': 1},
...     {'id': 3, 'name': 'Charlie', 'salary': 7000, 'manager_id': 1},
...     {'id': 4, 'name': 'Diana', 'salary': 9500, 'manager_id': 2}
... ]
>>> employees_earning_more_than_manager(employees)
['Bob', 'Diana']
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Build a dictionary mapping employee ID to their salary and manager_id.
Iterate through employees, skip those with manager_id None.
Compare salary with the manager's salary using the dictionary.
Collect names and sort alphabetically before returning.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.