# Null Counter

> How many holes in the data?

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list, return the count of None values.

## Worked solution and explanation

### Why this problem exists in real interviews

Counting None values tests **identity comparison** with `is None` vs. equality comparison. It is a data quality fundamentals check that reveals Python-specific knowledge.

---

### Break down the requirements

#### Step 1: Iterate through the list

Visit every element.

#### Step 2: Count elements that are None

Use `is None` for identity comparison, not `== None`.

---

### The solution

**Linear scan with identity check for None**

```python
def count_nulls(values):
    count = 0
    for value in values:
        if value is None:
            count += 1
    return count
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the list length.
> 
> **Space:** O(1). A single counter variable.

> **Interviewers Watch For**
>
> Using `is None` instead of `== None`. The `is` operator checks identity (the object is the singleton None), which is both faster and more correct. Some objects override `__eq__` in ways that make `== None` return True unexpectedly.

> **Common Pitfall**
>
> Counting falsy values instead of None. Values like `0`, `''`, `False`, and `[]` are falsy but are not None.

---

## Common follow-up questions

- What if you needed to count both None and empty strings? _(Tests combining two conditions with `or`.)_
- How would you compute the null rate as a percentage? _(Tests dividing the null count by the total count, handling the zero-length case.)_
- What is the difference between `is None` and `== None`? _(Tests understanding of identity vs. equality: `is` checks the object reference, `==` calls `__eq__`.)_

## Related

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