EasyNo. 0181
Employees Earning More Than Their Managers — LeetCode 181 Python Solution
- Topics
- Database
- Reading time
- 2 min
- Source
- leetcode.com
The problem
List the names of the employees who earn strictly more than their own manager. The Employee table has id (int, primary key), name (varchar), salary (int) and managerId (int), which holds the id of another employee and is null for someone with no manager. Return the names in a column called Employee.
Example
- Input
- Employee(id, name, salary, managerId) = (1, 'Dana', 70000, 3), (2, 'Ravi', 80000, 4), (3, 'Sam', 60000, null), (4, 'Maya', 90000, null)
- Output
- Employee = 'Dana'
- Explanation
- Dana earns 70000 while her manager Sam earns 60000; Ravi earns less than his manager Maya.
Python solution
import pandas as pd
def find_employees(employee: pd.DataFrame) -> pd.DataFrame:
merged = employee.merge(
employee, left_on="managerId", right_on="id", suffixes=("", "_manager")
)
result = merged[merged["salary"] > merged["salary_manager"]][["name"]]
result.columns = ["Employee"]
return resultComplexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0180 | Consecutive Numbers | Medium |
| 0182 | Duplicate Emails | Easy |
| 0183 | Customers Who Never Order | Easy |
| 0178 | Rank Scores | Medium |
| 0184 | Department Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
Frequently asked questions
- How hard is LeetCode 181. Employees Earning More Than Their Managers?
LeetCode 181. Employees Earning More Than Their Managers is rated Easy on LeetCode.
- What topics does LeetCode 181. Employees Earning More Than Their Managers cover?
LeetCode 181. Employees Earning More Than Their Managers is tagged Database on LeetCode.