# Quality Gate

> Not everything passes inspection.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of numbers, return True when every element is strictly greater than 0. An empty list returns True.

## Worked solution and explanation

### Why this problem exists in real interviews

Checking that all values pass a predicate is a basic **all-pass validation** pattern. It tests early termination on the first failure and correct handling of empty inputs.

---

### Break down the requirements

#### Step 1: Check each value against the predicate

Every number must be strictly greater than zero.

#### Step 2: Return False immediately on the first failure

Short-circuit evaluation: no need to scan the entire list once a non-positive value is found.

---

### The solution

**Short-circuit validation with early return**

```python
def all_positive(nums):
    for num in nums:
        if num <= 0:
            return False
    return True
```

> **Time and Space Complexity**
>
> **Time:** O(n) worst case, but often faster due to early termination.
> 
> **Space:** O(1). No auxiliary data structures.

> **Interviewers Watch For**
>
> Early return on the first failure rather than collecting all failures. For a gate check, you only need to know if any value fails.

> **Common Pitfall**
>
> Returning True for empty lists. Depending on requirements, an empty batch might be valid (vacuously true) or invalid. The standard convention treats empty as True (all zero elements satisfy the condition).

---

## Common follow-up questions

- What if zero should also pass the gate? _(Tests changing `<= 0` to `< 0` (non-negative check instead of strictly positive).)_
- How would you return which values failed? _(Tests collecting failing values or indices instead of returning a boolean.)_
- What if the gate should apply different rules to different columns? _(Tests a rule engine pattern with per-column predicate configuration.)_

## Related

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