# All Told

> Every shift leaves a number behind. Total the fleet.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Each value in `counts` is the number of events one server logged during a shift, and there is always at least one server. Return the fleet's combined total.

## Example 1

Input:

```
counts = [1,2,3,4,5]
```

Output:

```
15
```

## Example 2

Input:

```
counts = [10]
```

Output:

```
10
```

## Worked solution and explanation

### What's really being tested

This is a running total over a list whose length you don't control, dressed up as a fleet report. Nobody fails on the arithmetic; what separates candidates is whether the code survives a fleet of one and counts that can go negative. Hardcode `counts[0] + counts[1]` and a single-server shift raises an IndexError while a three-server shift comes back 300 short. Reach for `len` or `max` instead and a shift of `[-5, 5]` reports 2 or 5 where the real total is 0.

---

### The two decisions

#### Step 1: Start the total at zero

Zero is the identity for addition, so an empty-looking accumulator can't poison the result. Start it at the wrong value and every answer is off by a constant nobody notices until the totals look subtly wrong in prod.

#### Step 2: Fold each value in

Walk the list once and add each count to the running total. One pass, every element touched exactly once: there is no reason to index by position or build a second list.

---

### The solution

**Linear accumulation with a running total**

```python
def sum_list(counts):
    total = 0
    for value in counts:
        total += value
    return total
```

> **One pass, one variable**
>
> Time is O(n) where n is the list length: each element is added once. Space is O(1): a single accumulator variable, no matter how large the fleet grows.

> **Knowing `sum` and what it hides**
>
> Whether you reach for `sum(counts)` or write the loop. Both are correct; reaching for `sum` first, then offering to unroll it into a loop if they want to see the mechanics, reads as someone who knows the stdlib and knows what it costs.

> **A `return` inside the loop reports one server**
>
> Returning `total` from inside the loop instead of after it. The function exits on the very first server and reports its count as the whole fleet's. On a problem this short, this is the mistake interviewers actually catch.

---

## Common follow-up questions

- What if the list contains `None` values that should be skipped? _(Tests filtering within the accumulation loop.)_
- What if the counts were floats and floating-point precision mattered? _(Tests awareness of `math.fsum` or Kahan summation for reducing rounding error.)_
- How would you total only the servers whose count clears a threshold? _(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/all_told)
- [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). DataDriven is the data engineering interview community. Live code execution in SQL, Python, and Spark sandboxes. Every feature is open to every member.