EasyNo. 1873
Calculate Special Bonus — LeetCode 1873 Python Solution
- Topics
- Database
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
Table: Employees +-------------+---------+ | Column Name | Type | +-------------+---------+ | employee_id | int | | name | varchar | | salary | int | +-------------+---------+ employee_id is the primary key (column with unique values) for this table. Each row of this table indicates the employee ID, employee name, and salary.Example
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| employee_id | int |
| name | varchar |
| salary | int |
+-------------+---------+
employee_id is the primary key (column with unique values) for this table.
Each row of this table indicates the employee ID, employee name, and salary.Python solution
import duckdb
import pandas as pd
def solution(employees: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Employees", employees)
return con.execute("""SELECT
employee_id,
IF(
employee_id % 2 = 0
OR LEFT(name, 1) = 'M',
0,
salary
) AS bonus
FROM
employees
ORDER BY 1;""").df()Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 1873. Calculate Special Bonus?
LeetCode 1873. Calculate Special Bonus is rated Easy on LeetCode.
- What topics does LeetCode 1873. Calculate Special Bonus cover?
LeetCode 1873. Calculate Special Bonus is tagged Database on LeetCode.