From 9af5d2b05b6db478a1df0ad6cd950786703797ba Mon Sep 17 00:00:00 2001 From: tejas274 Date: Wed, 11 Jun 2025 15:41:15 -0500 Subject: [PATCH] problem 1 and 2 added --- problem1-177-nth-highest-salary.py | 13 +++++++++++++ problem2-176-second-highest-salary.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 problem1-177-nth-highest-salary.py create mode 100644 problem2-176-second-highest-salary.py diff --git a/problem1-177-nth-highest-salary.py b/problem1-177-nth-highest-salary.py new file mode 100644 index 0000000..a9dde97 --- /dev/null +++ b/problem1-177-nth-highest-salary.py @@ -0,0 +1,13 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + + df = employee[['salary']].drop_duplicates() + + if N <= 0 or N > len(df): + res = None + else: + res = df.sort_values(by=['salary'], ascending = False).head(N).tail(1) + res = res['salary'].values[0] + + return pd.DataFrame({f'getNthHighestSalary({N})': [res]}) \ No newline at end of file diff --git a/problem2-176-second-highest-salary.py b/problem2-176-second-highest-salary.py new file mode 100644 index 0000000..c92c81a --- /dev/null +++ b/problem2-176-second-highest-salary.py @@ -0,0 +1,13 @@ +import pandas as pd + + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + df = employee[['salary']].drop_duplicates() + + if len(df) < 2: + res = None + else: + res = df.sort_values(by=['salary'], ascending=False).head(2).tail(1) + res = res['salary'].values[0] + + return pd.DataFrame({'SecondHighestSalary': [res]}) \ No newline at end of file