Find Employees in Their Department’s Top Three Salary Levels
Company: Bloomberg
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: hard
Interview Round: Other
### Problem
Find all high earners in each department: a high earner has one of that department’s three largest distinct salaries. Return Department, Employee and Salary in any order. Retain every employee tied at an included salary level. Only employees with a recorded department and a known salary participate.
### Tables
Table: `Employee`
```text
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
+--------------+---------+
id is the primary key (column with unique values) for this table.
departmentId is a foreign key (reference column) of the ID from the Department table.
Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
```
Table: `Department`
```text
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key (column with unique values) for this table.
Each row of this table indicates the ID of a department and its name.
```
### Example
```text
Department (id,name): (1,Build)
Employee (id,name,salary,departmentId): (1,Ada,100,1), (2,Bo,90,1), (3,Cam,90,1), (4,Dee,80,1), (5,Eli,70,1)
Output (Department,Employee,Salary): (Build,Ada,100), (Build,Bo,90), (Build,Cam,90), (Build,Dee,80)
```
### Constraints
No two employee rows have exactly the same name, salary and department together.
### What a Strong Answer Covers
- Identify the three largest distinct known salary values in each department.
- Return every employee at those values, including all ties.
### Follow-up Questions
- How would the result change if each department needed exactly three people when available?
- How would you make the number of salary levels configurable?
Overview: Find employees at the three highest distinct salary levels in their departments, including ties.
Find all high earners in each department: a high earner has one of that department’s three largest distinct salaries. Return Department, Employee and Salary in any order. Retain every employee tied at an included salary level. Only employees with a recorded department and a known salary participate.
Tables
Table: Employee
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| id | int |
| name | varchar |
| salary | int |
| departmentId | int |
+--------------+---------+
id is the primary key (column with unique values) for this table.
departmentId is a foreign key (reference column) of the ID from the Department table.
Each row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.
Table: Department
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
+-------------+---------+
id is the primary key (column with unique values) for this table.
Each row of this table indicates the ID of a department and its name.