Interview Questions
In today’s AI-driven world, we often turn to AI for help with solving problems. It can offer ideas, analyze information, and suggest different approaches. But it is still up to us to decide which approach is most effective, organize the workflow, and guide the process toward the right solution.
AI suggests number of ways but human has to choose the effective one.
The following are basic problem-solving questions that interviewers may ask at random to assess an interviewee’s fundamental understanding. They are available on the StrataScratch platform.
Duplicate HR Department Employees
Generate a list of employees who work in the HR department, including only their first names and department in the output. Each employee should appear twice in the list, meaning their first name and department should be duplicated in the output.
DataFrame
worker
worker
worker_id:int64
first_name:object
last_name:object
salary:int64
joining_date:datetime64[ns]
Get Akshima Aggarwal’s stories in your inbox
Join Medium for free to get updates from this writer.
department:object
Steps to solve the Question:
- Find all the employees where department is HR.
- List all employees which appear twice in the list .
Using Python-Pandas
import pandas as pd
worker.head()
df= worker
df=df[df['department']=='HR']
df1=df.loc[df.index.repeat(2)]
df1[['first_name','department']]Using MySQL
select first_name, department from worker where department Like 'HR'
UNION ALL
select first_name, department from worker where department Like 'HR'
order by first_name;Output:
Employees With the Same Salary
Find employees who earn the same salary.
Output the worker id along with the first name and the salary in descending order.
DataFrame is same as former problem
Steps to solve this question
- Find the employees who are having the same salary.
- Then sort the values in descending order.
Using Python-Pandas
import pandas as pd
worker.head()
df=worker
df=df[df.duplicated(subset=['salary'],keep=False)]
df=df.sort_values(by='salary',ascending=False)
df[['worker_id','first_name','salary']]Duplicated Function is used to find out duplicate values based on salary in a DataFrame and keep parameter helps in having both values in the output.
Using MySQL
SELECT worker_id, first_name, salary
FROM worker
WHERE salary IN (
SELECT salary
FROM worker
GROUP BY salary
HAVING COUNT(*) > 1
)
ORDER BY salary desc;






