Junior-Level Python and SQL Interview Prep
Python Q1: Count Occurrences in a List
Problem:
Given a list of numbers, count how many times each number appears.
Python Code:
from collections import Counter
numbers = [1, 2, 2, 3, 4, 4, 4, 5]
count = Counter(numbers)
print(count)
Explanation:
Counter is a dictionary subclass that counts the frequency of elements.
Python Q2: Remove Duplicates from a List
Problem:
Remove duplicates from a list while preserving order.
Python Code:
numbers = [1, 2, 2, 3, 4, 4, 5]
unique = list([Link](numbers))
print(unique)
Explanation:
[Link] removes duplicates while keeping the first occurrence.
Python Q3: Read CSV and Remove NaN Rows
Problem:
Read a CSV file and remove rows with missing values.
Junior-Level Python and SQL Interview Prep
Python Code:
import pandas as pd
df = pd.read_csv("[Link]")
df_clean = [Link]()
print(df_clean)
Explanation:
pandas dropna() removes rows containing NaN (missing) values.
Python Q4: Reverse Words in a Sentence
Problem:
Reverse the words in a sentence.
Python Code:
sentence = "Data engineering is fun"
reversed_sentence = " ".join([Link]()[::-1])
print(reversed_sentence)
Explanation:
split() turns the sentence into a list of words, and [::-1] reverses it.
SQL Q1: Count Employees per Department
SQL:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;
Explanation:
Groups rows by department and counts the number of employees in each.
Junior-Level Python and SQL Interview Prep
SQL Q2: Find the Second Highest Salary
SQL:
SELECT MAX(salary) AS SecondHighest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Explanation:
This finds the highest salary that is less than the maximum salary.
SQL Q3: Filter Employees with High Salary
SQL:
SELECT name, salary
FROM employees
WHERE salary > 50000;
Explanation:
Retrieves employees earning more than 50,000.
SQL Q4: Join Employees with Departments
SQL:
SELECT [Link], d.department_name
FROM employees e
JOIN departments d ON e.department_id = [Link];
Explanation:
Performs an inner join to link employees with their department names.