An average salary is pulled around by one very large one. Compensation wants the median instead.
One row per dept, with the columns:
deptheadcount — every employee in the department, salary recorded or notmedian_salary — the exact median of the recorded salaries, rounded to 2 decimal places, or null if none were recordedFor an even number of recorded salaries the median is the mean of the two middle ones.
| dept | salary |
|---|---|
| OPS | 10.0 |
| OPS | 20.0 |
| dept | headcount | median_salary |
|---|---|---|
| OPS | 2 | 15.0 |
15.0 is the answer even though nobody earns it.
employees| dept | emp_id | salary |
|---|---|---|
| ENG | 1 | 100 |
| ENG | 2 | 200 |
| ENG | 3 | 300 |
| OPS | 4 | 10 |
| OPS | 5 | 20 |
| dept | headcount | median_salary |
|---|---|---|
| ENG | 3 | 200 |
| OPS | 2 | 15 |
employees| dept | emp_id | salary |
|---|---|---|
| LEGAL | 1 | 75.5 |
| SALES | 2 | 10 |
| SALES | 3 | 30 |
| SALES | 4 | 50 |
| SALES | 5 | 70 |
| dept | headcount | median_salary |
|---|---|---|
| LEGAL | 1 | 75.5 |
| SALES | 4 | 40 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.