# The Peak Finder

> Largest number in the list. Max() is not an option.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of integers, return the maximum value without using max(). Return None if empty.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests the most basic **linear scan accumulation** pattern. By prohibiting `max()`, interviewers check whether candidates understand how maximum-finding actually works under the hood.

---

### Break down the requirements

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

Set the current maximum to `nums[0]`. This handles the case where all numbers are negative.

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

Compare each element to the current maximum. Update if the element is larger.

#### Step 3: Return the maximum

After scanning all elements, the tracked value is the largest.

---

### The solution

**Linear scan with running maximum**

```python
def find_max(nums):
    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) with a single pass.
> 
> **Space:** O(1). One tracking variable.

> **Interviewers Watch For**
>
> Do you initialize `largest` to `nums[0]` instead of 0 or negative infinity? Using 0 fails for all-negative lists. Using negative infinity works but is less clean than using the first element.

> **Common Pitfall**
>
> Starting the loop at index 0 instead of 1. This works but wastes one comparison comparing `nums[0]` with itself.

---

## Common follow-up questions

- How would you also return the index of the maximum? _(Tests tracking the index alongside the value.)_
- What if you needed both the max and min in a single pass? _(Tests tracking two variables simultaneously.)_
- Can you find the max with fewer than n-1 comparisons? _(Tests tournament-style comparison or proving the lower bound of n-1.)_

## Related

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