From 68a6fc39cf5d5ef8be742e05cd13062fa847f748 Mon Sep 17 00:00:00 2001 From: Sangeeth Santhosh <73825180+sangeeths29@users.noreply.github.com> Date: Thu, 12 Jun 2025 22:27:16 -0700 Subject: [PATCH] Add files via upload --- 01-DepartmentHighestSalary.py | 12 ++++++++++++ 02-RankScores.py | 8 ++++++++ 2 files changed, 20 insertions(+) create mode 100644 01-DepartmentHighestSalary.py create mode 100644 02-RankScores.py diff --git a/01-DepartmentHighestSalary.py b/01-DepartmentHighestSalary.py new file mode 100644 index 0000000..64d7711 --- /dev/null +++ b/01-DepartmentHighestSalary.py @@ -0,0 +1,12 @@ +# Problem 1 - Department Highest Salary (https://leetcode.com/problems/department-highest-salary/ ) +import pandas as pd + +def department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame: + # Join Employee and Department Table via Inner Join + df = employee.merge(department, left_on = 'departmentId', right_on = 'id', how = 'inner') + # Compute Maximum Salary Per Department + max_salary = df.groupby('departmentId')['salary'].transform('max') + # Filter only those rows where salary is equal to max_salary + df = df[df['salary'] == max_salary] + # Return final dataframe with renamed columns + return df[['name_y', 'name_x', 'salary']].rename(columns = {'name_y' : 'Department', 'name_x' : 'Employee'}) \ No newline at end of file diff --git a/02-RankScores.py b/02-RankScores.py new file mode 100644 index 0000000..8c00d8e --- /dev/null +++ b/02-RankScores.py @@ -0,0 +1,8 @@ +# Problem 2 - Rank Scores ( https://leetcode.com/problems/rank-scores/ ) +import pandas as pd + +def order_scores(scores: pd.DataFrame) -> pd.DataFrame: + # Rank scores by dense rank method in pandas + scores['rank'] = scores['score'].rank(ascending = False, method = 'dense') + # Sort the table by rank in ascending order + return scores[['score', 'rank']].sort_values(by=['rank']) \ No newline at end of file