You are given the following interview tasks. Write solutions in SQL and/or Python (pandas) as appropriate.
Task 1 — Second highest salary
You have a table:
employees
-
employee_id
INT (PK)
-
name
VARCHAR
-
salary
INT
Return the second highest distinct salary.
-
If there is
no
second distinct salary, return
NULL
.
Required output
-
second_highest_salary
(INT or NULL)
Task 2 — Merge two datasets
You are given two datasets that share a common key:
users
-
user_id
INT (PK)
-
country
VARCHAR
-
signup_date
DATE
user_events
-
user_id
INT (FK → users.user_id)
-
event_time
TIMESTAMP
-
event_type
VARCHAR
Merge them so that each event row is enriched with user attributes.
-
Keep only events that have a matching
user_id
in
users
(inner join).
Required output
-
user_id
,
country
,
signup_date
,
event_time
,
event_type
Task 3 — “Run out the budget” (maximize hires)
You have a list/table of employees with their salaries and a total hiring budget B.
-
Each employee costs exactly their
salary
.
-
You can hire at most once per employee.
-
Goal:
maximize the number of employees hired
without exceeding the budget.
Input
-
employees(employee_id, salary)
and an integer
B
Required output
Clarify any assumptions you need (e.g., what to do if B <= 0).