# The High Mark

> Scan the list. Report the max.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of integers, return the maximum value. Return None if the list is empty.

## Worked solution and explanation

### Why this problem exists in real interviews

This is the simplest possible list operation: finding the maximum. It tests whether a candidate handles the **empty list edge case** and can write a clean linear scan.

---

### Break down the requirements

#### Step 1: Handle empty input

Return `None` if the list has no elements.

#### Step 2: Scan for the largest value

Initialize with the first element and compare each subsequent element.

---

### The solution

**Linear scan with empty check**

```python
def find_max(nums: list):
    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.
> 
> **Space:** O(1). Single tracking variable.

> **Interviewers Watch For**
>
> How you handle the empty list. Returning `None`, raising an exception, or returning negative infinity are all valid choices depending on the API contract.

> **Common Pitfall**
>
> Initializing the max to 0 or `float('-inf')` instead of the first element. Using 0 fails for all-negative lists.

---

## Common follow-up questions

- What if you also needed the index of the maximum? _(Tests tracking both value and index during the scan.)_
- How would you find the second largest without sorting? _(Tests maintaining two tracking variables.)_
- What is the time complexity of Python's built-in max()? _(Tests knowledge that it is O(n), same as the manual approach.)_

## Related

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