diff --git a/README.md b/README.md index 1d75af9..2b4c85d 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,51 @@ 1 Problem 1 :Calculate Special Bonus ( https://leetcode.com/problems/calculate-special-bonus/) +Write a solution to calculate the bonus of each employee. The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee's name does not start with the character 'M'. The bonus of an employee is 0 otherwise. + +Return the result table ordered by employee_id. + +The result format is in the following example. + + +------------------------------------------------ +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + employees['bonus'] = employees.apply( + lambda row: row['salary'] if row['employee_id'] % 2 == 1 and not row['name'].startswith('M') else 0, + axis=1 + ) + return employees[['employee_id', 'bonus']].sort_values('employee_id') + + 2 Problem 2 : Fix Names in a Table ( https://leetcode.com/problems/fix-names-in-a-table/ ) +Write a solution to fix the names so that only the first character is uppercase and the rest are lowercase. + +Return the result table ordered by user_id. + +The result format is in the following example. +------------------------------------------------ + +import pandas as pd + +def fix_names(users: pd.DataFrame) -> pd.DataFrame: + users['name'] = users['name'].str.capitalize() + return users.sort_values('user_id') + 3 Problem 3 : Patients with a Condition ( https://leetcode.com/problems/patients-with-a-condition/) +Write a solution to find the patient_id, patient_name, and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix. + +Return the result table in any order. +The result format is in the following example. +------------------------------------------------ +import pandas as pd +def patients_with_a_condition(patients: pd.DataFrame) -> pd.DataFrame: + return patients[patients['conditions'].str.contains(r'\bDIAB1', regex=True)]