Calculate Salaries - Problem
Given a table Salaries with employee information and their salaries, calculate the after-tax salaries for all employees.
The tax rate is determined by the maximum salary in each company:
- 0% tax if max salary < $1000
- 24% tax if max salary is between $1000-$10000 (inclusive)
- 49% tax if max salary > $10000
Return the employee details with their after-tax salary rounded to the nearest integer.
Table Schema
Salaries
| Column Name | Type | Description |
|---|---|---|
company_id
PK
|
int | Company identifier |
employee_id
PK
|
int | Employee identifier |
employee_name
|
varchar | Employee name |
salary
|
int | Employee salary before tax |
Primary Key: (company_id, employee_id)
Note: Each row represents an employee with their company and salary information
Input & Output
Example 1 — Mixed Tax Brackets
Input Table:
| company_id | employee_id | employee_name | salary |
|---|---|---|---|
| 1 | 1 | Tony | 2000 |
| 1 | 2 | Pronub | 21300 |
| 1 | 3 | Tyson | 10000 |
| 2 | 1 | Pam | 300 |
| 2 | 7 | Bassem | 450 |
Output:
| company_id | employee_id | employee_name | salary |
|---|---|---|---|
| 1 | 1 | Tony | 1020 |
| 1 | 2 | Pronub | 10863 |
| 1 | 3 | Tyson | 5100 |
| 2 | 1 | Pam | 300 |
| 2 | 7 | Bassem | 450 |
💡 Note:
Company 1: Max salary is 21300 (>10000), so 49% tax applies. Tony: 2000 × 0.51 = 1020, Pronub: 21300 × 0.51 = 10863, Tyson: 10000 × 0.51 = 5100.
Company 2: Max salary is 450 (<1000), so 0% tax applies. All salaries remain unchanged.
Example 2 — Medium Tax Bracket
Input Table:
| company_id | employee_id | employee_name | salary |
|---|---|---|---|
| 3 | 1 | Alice | 5000 |
| 3 | 2 | Bob | 8000 |
Output:
| company_id | employee_id | employee_name | salary |
|---|---|---|---|
| 3 | 1 | Alice | 3800 |
| 3 | 2 | Bob | 6080 |
💡 Note:
Company 3: Max salary is 8000 (between 1000-10000), so 24% tax applies. Alice: 5000 × 0.76 = 3800, Bob: 8000 × 0.76 = 6080.
Constraints
-
1 ≤ company_id ≤ 100 -
1 ≤ employee_id ≤ 1000 -
1 ≤ employee_name.length ≤ 100 -
300 ≤ salary ≤ 100000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Employee salaries by company
2
Window Function
Find max salary per company
3
Tax Calculation
Apply tax rates and round
Key Takeaway
🎯 Key Insight: Use window functions to efficiently determine company-wide tax rates based on maximum salaries
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code