# Transform Column

> Same data, new shape.

Canonical URL: <https://datadriven.io/problems/transform_column>

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of numbers, return a new list where each element is the square of the corresponding input.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **list transformation**, the simplest form of a map operation. It probes whether a candidate can apply a function to every element and collect results, a pattern used in every data pipeline.

---

### Break down the requirements

#### Step 1: Iterate through the input list

Apply the squaring operation to each element.

#### Step 2: Collect results in a new list

Append each squared value to the result.

---

### The solution

**Element-wise squaring with loop accumulation**

```python
def square_column(values: list) -> list:
    result = []
    for val in values:
        result.append(val * val)
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(n) for a single pass.
> 
> **Space:** O(n) for the result list.

> **Interviewers Watch For**
>
> Using `val * val` instead of `val ** 2`. Both work, but multiplication is slightly faster and avoids the exponentiation overhead for simple squares.

> **Common Pitfall**
>
> Modifying the input list in place when the prompt asks for a new list. Always create a separate result unless explicitly told to mutate.

---

## Common follow-up questions

- What if the transformation function was passed as a parameter? _(Tests higher-order functions: accepting a callable and applying it.)_
- How would you handle None values in the input? _(Tests adding a guard to skip or replace None entries.)_
- How does this relate to pandas' apply() or map()? _(Tests awareness of vectorized operations in data libraries.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/transform_column)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.