# The Forbidden Ceiling

> Round up. But not the obvious way.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a non-empty list of integers, return the maximum. You may not use max() or any sort/sorted helper. Runtime must be O(n).

## Worked solution and explanation

### Why this problem exists in real interviews

This tests whether a candidate can implement a **basic linear scan** without relying on built-in functions. It probes understanding of comparison-based algorithms at the most fundamental level.

---

### Break down the requirements

#### Step 1: Initialize with the first element

Use the first element as the initial maximum.

#### Step 2: Scan the rest of the list

Compare each element to the current maximum and update if larger.

---

### The solution

**Linear scan maximum**

```python
def find_max(nums: list) -> int:
    if not nums:
        return None
    largest = nums[0]
    for i in range(1, len(nums)):
        if nums[i] > largest:
            largest = nums[i]
    return largest
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the list length. Every element is checked exactly once.
> 
> **Space:** O(1). Only one tracking variable.

> **Interviewers Watch For**
>
> Whether you handle the empty list case. Returning `None` is the safest choice; returning `float('-inf')` is also acceptable depending on the API contract.

> **Common Pitfall**
>
> Initializing the maximum to 0. This fails for lists of all negative numbers. Always initialize with the first element.

---

## Common follow-up questions

- How would you find both min and max in a single pass? _(Tests tracking two variables simultaneously.)_
- Can you find the max with fewer than n-1 comparisons? _(Tests the tournament algorithm, which uses 3n/2 - 2 comparisons.)_
- What if the list is extremely large and distributed? _(Tests MapReduce pattern: find local maxima, then global max.)_

## Related

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