# Column Sum

> Add up the column. Every value counts.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a non-empty list of numbers, return the sum.

## Worked solution and explanation

### Why this problem exists in real interviews

Summing a list is the simplest possible aggregation and tests whether you can write a correct accumulator loop. It is often the first question in a screen to calibrate speed and coding style.

---

### Break down the requirements

#### Step 1: Initialize an accumulator to zero

Zero is the identity element for addition, making it the correct starting value.

#### Step 2: Add each element

Iterate through the list and add each value to the running total.

---

### The solution

**Linear accumulation with a running total**

```python
def sum_list(nums):
    total = 0
    for num in nums:
        total += num
    return total
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the list length. Each element is added once.
> 
> **Space:** O(1). A single accumulator variable.

> **Interviewers Watch For**
>
> Whether you reach for `sum()` or write the loop manually. In an interview setting where the prompt says 'implement,' writing the loop shows you understand what `sum()` does internally.

> **Common Pitfall**
>
> Returning `total` inside the loop instead of after it. This returns early on the first iteration.

---

## Common follow-up questions

- What if the list contains None values that should be skipped? _(Tests filtering within the accumulation loop.)_
- What if floating-point precision matters? _(Tests awareness of `math.fsum` or Kahan summation for reducing rounding error.)_
- How would you sum only values that pass a predicate? _(Tests combining filter logic with accumulation in a single pass.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/column_sum)
- [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.