You're working as a data analyst for a company and need to investigate salary discrepancies. Given an Employee database table, your task is to find all employees who earn more than their direct managers.
The Employee table contains information about each employee including their ID, name, salary, and their manager's ID. Your goal is to identify potential salary inconsistencies where subordinates earn more than their supervisors.
| Column Name | Type |
|---|---|
| id | int |
| name | varchar |
| salary | int |
| managerId | int |
Note: The id is the primary key. Some employees may not have a manager (managerId is null for top-level executives).
Return: The names of all employees who earn more than their managers, in any order.
Input & Output
Visualization
Time & Space Complexity
Database can optimize the join using indexes, typically resulting in O(n log n) complexity
Space for the result set and any temporary join tables
Constraints
- 1 โค Employee table rows โค 104
- All employee IDs are unique
- salary values are positive integers
- managerId can be null for top-level employees
- No circular management relationships exist