---
title: "Altimetrik Interview Questions: Python, SQL, PySpark Practice"
description: "Prepare for Altimetrik interviews with these 10 essential Python, SQL, and PySpark questions and solutions. Covers coding, data transformation, and real-world problem-solving for 2025"
url: https://srinimf.com/2025/09/11/altimetrik-interview-questions-2025-python-sql-and-pyspark-explained/
date: 2025-09-11
modified: 2026-10-11
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2025/09/pexels-photo-7731360.jpeg?fit=1782%2C1300&ssl=1
categories: ["PySpark"]
tags: ["AltimetrikInterview", "DataEngineering", "PIVOT", "PySparkInterview", "PythonInterview", "SQLInterview", "UNPIVOT"]
type: post
lang: en
---

# Altimetrik Interview Questions: Python, SQL, PySpark Practice

### Introduction

Are you preparing for an [interview at Altimetrik](https://srinimf.com/2025/09/24/top-pyspark-interview-questions/) or a similar data engineering/analytics company? 🚀
Altimetrik interviews often focus on **problem-solving skills** in **Python, SQL, and PySpark**, with a mix of coding challenges and conceptual questions.

Related[Top PySpark & AWS Glue Q&A for Big Data Practitioners](https://srinimf.com/2025/09/24/top-pyspark-aws-glue-qa-for-big-data-practitioners/)

In this blog, we’ll cover **10 real-world interview-style questions with detailed solutions**—ranging from Python coding (strings, decorators, arrays), SQL queries (joins, aggregation, [window functions](https://www.postgresql.org/docs/current/functions-window.html)), and PySpark transformations (pivot, explode, deduplication).

By the end of this [guide](https://srinimf.com/about/), you’ll have a **solid practice set** to boost your confidence for technical interviews.

### 🔟 Questions Covered

1. Python – First non-repetitive character in a string
2. Python – Rearrange an array so negatives come first
3. Python – Decorator to log function execution time
4. Python – Flatten a nested list
5. SQL – Latest transaction and total transactions per credit card
6. SQL – Departments with more than 5 employees
7. SQL – Match results summary (played, won, lost, draw per team)
8. PySpark – Remove duplicates by keeping the latest row
9. PySpark – Pivot sales data by year
10. PySpark – Explode comma-separated values into rows

# Altimetrik-Style Interview Practice Questions

## 🐍 Python (4 Questions)

### **Q1. [First non-repetitive character](https://docs.python.org/3/library/collections.html) in a string**

**Problem:** Given a string, return the first character that does not repeat.

**Solution:**

```
from collections import Counterdef first_non_repeating(s: str):    freq = Counter(s)    for c in s:        if freq[c] == 1:            return c    return Noneprint(first_non_repeating("swiss"))  # w
```

### **Q2. Rearrange an array so that negatives come first**

**Problem:** Input `[3, -2, -1, 5, 4, -3]` → Output `[-2, -1, -3, 3, 5, 4]` (order within groups not important).

**Solution:**

```
def segregate(arr):    i, j = 0, len(arr)-1    while i < j:        if arr[i] < 0:            i += 1        elif arr[j] >= 0:            j -= 1        else:            arr[i], arr[j] = arr[j], arr[i]    return arrprint(segregate([3, -2, -1, 5, 4, -3]))
```

### **Q3. Write a [decorator](https://peps.python.org/pep-0318/) that logs function execution time**

**Solution:**

```
import timedef log_time(func):    def wrapper(*args, **kwargs):        start = time.time()        result = func(*args, **kwargs)        print(f"{func.__name__} took {time.time() - start:.4f}s")        return result    return wrapper@log_timedef add_numbers(a, b):    return a + bprint(add_numbers(5, 7))
```

### **Q4. Flatten a nested list**

**Problem:** `[1, [2, [3, 4], 5], 6] → [1,2,3,4,5,6]`

**Solution:**

```
def flatten(lst):    out = []    for x in lst:        if isinstance(x, list):            out.extend(flatten(x))        else:            out.append(x)    return outprint(flatten([1, [2, [3, 4], 5], 6]))
```

## 🗄 SQL (3 Questions)

### **Q5. Latest transaction and total transactions per credit card**

**Table:** `transactions(credit_card_id, transaction_date, amount)`

**Solution:**

```
%sqlCREATE TABLE transactions (    credit_card_id INT,    transaction_date DATE,    amount DECIMAL(10,2));%sqlINSERT INTO transactions (credit_card_id, transaction_date, amount) VALUES(101, &apos;2025-01-05&apos;, 250.00),(101, &apos;2025-01-10&apos;, 300.00),(101, &apos;2025-02-02&apos;, 150.00),(102, &apos;2025-01-15&apos;, 500.00),(102, &apos;2025-01-20&apos;, 200.00),(103, &apos;2025-02-01&apos;, 450.00),(103, &apos;2025-02-10&apos;, 600.00),(103, &apos;2025-03-05&apos;, 350.00);
```

Related[Mastering SQL Date Extraction and Monthly Trends Using LAG()](https://srinimf.com/2025/10/14/mastering-sql-date-extraction-and-monthly-trends-using-lag/)

```
SELECT    credit_card_id,    COUNT(*) AS total_txns,    MAX(transaction_date) AS latest_txnFROM transactionsGROUP BY credit_card_id;
```

### **Q6. Departments with > 5 employees**

**Tables:** `employees(emp_id, dept_id)` and `departments(dept_id, dept_name)`

**Solution:**

```
WITH dept_counts AS (    SELECT dept_id, COUNT(*) AS emp_count    FROM employees    GROUP BY dept_id)SELECT d.dept_name, dc.emp_countFROM departments dJOIN dept_counts dc  ON d.dept_id = dc.dept_idWHERE dc.emp_count > 5;
```

### **Q7. Match results summary**

**Table:** `matches(team_a, team_b, score_a, score_b)` → find total played, won, lost, draw per team.

**Solution:**

```
%sqlCREATE TABLE matches (    team_a VARCHAR(50),    team_b VARCHAR(50),    score_a INT,    score_b INT);%sqlINSERT INTO matches (team_a, team_b, score_a, score_b) VALUES(&apos;India&apos;,   &apos;Australia&apos;, 250, 200),  -- India wins(&apos;India&apos;,   &apos;England&apos;,   180, 180),  -- Draw(&apos;Australia&apos;,&apos;England&apos;,  220, 230),  -- England wins(&apos;India&apos;,   &apos;Australia&apos;, 210, 220),  -- Australia wins(&apos;England&apos;, &apos;India&apos;,     190, 200),  -- India wins(&apos;England&apos;, &apos;Australia&apos;, 300, 300);  -- Draw
```

```
%sqlwith cte as (  select team_a as team, score_a as score, score_b as opponent  from matches   union all  select team_b as team, score_b as score , score_a as opponent  from matches)select team,        count(*) as all_played,        sum(case when score > opponent then 1 else 0 end) as wins,        sum(case when score < opponent then 1 else 0 end ) as lost,        sum(case when score = opponent then 1 else 0 end) as draw        from cte        group by team        order by team
```

## 🔥 PySpark (3 Questions)

### **Q8. Remove duplicates by keeping latest row**

**Data:** `(id, value, updated_at)` → [keep only the latest record per id by removing duplicates](https://spark.apache.org/docs/3.5.6/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.dropDuplicates.html).

**Solution:**

```
from pyspark.sql import functions as F, Windoww = Window.partitionBy("id").orderBy(F.col("updated_at").desc())df_latest = df.withColumn("rn", F.row_number().over(w)) \              .filter("rn = 1") \              .drop("rn")
```

### **Q9. Pivot sales data by year**

**Data:** `(region, year, sales)` → [pivot years as columns](https://spark.apache.org/docs/latest/api/python/reference/pyspark.pandas/api/pyspark.pandas.DataFrame.pivot.html).

**Solution:**

```
from pyspark.sql import SparkSessionfrom pyspark.sql.functions import *spark = SparkSession.builder.appName("PivotExample").getOrCreate()#PIVOTdata = (["East", 1000, 2022], ["West", 2000, 2022], ["East", 3000, 2022], ["West", 4000, 2022], ["East", 5000, 2023], ["West", 6000, 2024])schema = ["Region", "Sales", "Year"]df = spark.createDataFrame(data, schema)df = df.groupBy("Region").pivot("Year").sum("Sales")df.show()#UNPIVOTdf1 = df.selectExpr("Region",             stack(3, &apos;2022&apos;,&apos;2022&apos;, &apos;2022&apos;, &apos;2022&apos;,&apos;2023&apos;,&apos;2024&apos;)as(Year,Sales)))df1.show()
```

[Learn more about pivot and unpivot in PySpark](https://srinimf.com/pivot-vs-unpivot-in-pyspark/).

### **Q10. Explode comma-separated values into rows**

**Data:** `(Name, Sports)` → `"Alice", "Badminton,Tennis"` → 2 rows using [explode to expand comma-separated values into rows](https://spark.apache.org/docs/latest/api/python/reference/pyspark.pandas/api/pyspark.pandas.DataFrame.explode.html).

**Solution:**

```
from pyspark.sql.functions import split, explode, trimdf2 = df.withColumn("Sport", explode(split("Sports", ",")))df2 = df2.withColumn("Sport", trim(df2["Sport"]))df2.show()
```

## Extra Questions

### **Q1. Write a SQL query to find the most recent order date for each customer from the `orders1` table, but only include orders placed within the last 30 days.**

```
-- 1. Create tableCREATE TABLE orders1 (    id INT AUTO_INCREMENT PRIMARY KEY,    name VARCHAR(100),    amount DECIMAL(10,2),    ordered_date DATE);-- 2.Insert valuesINSERT INTO orders1 (name, amount, ordered_date) VALUES(&apos;Alice&apos;, 250.00, &apos;2025-09-10&apos;),(&apos;Bob&apos;, 180.50, &apos;2025-09-05&apos;),(&apos;Charlie&apos;, 320.75, &apos;2025-08-30&apos;),(&apos;David&apos;, 150.00, &apos;2025-08-01&apos;),   -- older than 30 days(&apos;Eva&apos;, 500.00, &apos;2025-09-13&apos;),(&apos;Frank&apos;, 275.00, &apos;2025-09-01&apos;),(&apos;Grace&apos;, 420.00, &apos;2025-09-07&apos;);-- 3. Solutionselect name,        max(ordered_date) as recent_from_orderswhere datediff(CURDATE(), ordered_date) < 30group by name;
```

### Q2. Write a SQL query to find, for each month, the customer who spent the **highest total amount**. If a customer has multiple orders in the same month, sum them first before comparing with others.

```
-- Create tableCREATE TABLE orders (    id INT AUTO_INCREMENT PRIMARY KEY,    name VARCHAR(100),    amount DECIMAL(10,2),    ordered_date DATE);-- Insert sample data across different monthsINSERT INTO orders (name, amount, ordered_date) VALUES(&apos;Alice&apos;,   200.00, &apos;2025-01-05&apos;),(&apos;Bob&apos;,     450.00, &apos;2025-01-12&apos;),(&apos;Charlie&apos;, 300.00, &apos;2025-01-20&apos;),(&apos;Alice&apos;,   500.00, &apos;2025-02-03&apos;),(&apos;David&apos;,   350.00, &apos;2025-02-15&apos;),(&apos;Eva&apos;,     700.00, &apos;2025-02-25&apos;),-- March(&apos;Frank&apos;,   600.00, &apos;2025-03-08&apos;),(&apos;Grace&apos;,   750.00, &apos;2025-03-16&apos;),(&apos;Helen&apos;,   400.00, &apos;2025-03-30&apos;),-- April(&apos;Alice&apos;,   900.00, &apos;2025-04-02&apos;),(&apos;Bob&apos;,     650.00, &apos;2025-04-18&apos;),(&apos;Charlie&apos;, 800.00, &apos;2025-04-25&apos;),-- May(&apos;David&apos;,   1000.00, &apos;2025-05-05&apos;),(&apos;Eva&apos;,      950.00, &apos;2025-05-10&apos;),(&apos;Frank&apos;,    720.00, &apos;2025-05-20&apos;);WITH CTE1 AS (  SELECT NAME,   SUM(AMOUNT) as totamt,   DATE_FORMAT(ordered_date, &apos;%Y-%m&apos;) as month  from orders  group by name,DATE_FORMAT(ordered_date, &apos;%Y-%m&apos;)),CTE2 as(  select name,   totamt,   month,   row_number()over(PARTITION BY month order by totamt desc) as rn  from CTE1)select name,  totamt,   month   from CTE2   where rn =1;
```

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2025%2F09%2F11%2Faltimetrik-interview-questions-2025-python-sql-and-pyspark-explained%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2025%2F09%2Fpexels-photo-7731360.jpeg%3Ffit%3D1200%252C875%26ssl%3D1&description=Altimetrik%20Interview%20Questions%3A%20Python%2C%20SQL%2C%20PySpark%20Practice)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2025/09/11/altimetrik-interview-questions-2025-python-sql-and-pyspark-explained/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2025/09/11/altimetrik-interview-questions-2025-python-sql-and-pyspark-explained/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2025/09/11/altimetrik-interview-questions-2025-python-sql-and-pyspark-explained/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2025/09/11/altimetrik-interview-questions-2025-python-sql-and-pyspark-explained/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Altimetrik%20Interview%20Questions%3A%20Python%2C%20SQL%2C%20PySpark%20Practice&body=https%3A%2F%2Fsrinimf.com%2F2025%2F09%2F11%2Faltimetrik-interview-questions-2025-python-sql-and-pyspark-explained%2F&share=email)
-

### Like this:

Like Loading…
