# No Shortcuts

> The peak value. Built-ins off the table.

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

Domain: Python · Difficulty: easy · Seniority: L6

## Problem

Given a list of numbers, return its maximum without using max(). Return None if empty.

## Worked solution and explanation

### Why this problem exists in real interviews

Implementing max without built-ins tests whether you can write a correct **linear scan with a running accumulator** from scratch. It is a fundamentals check that every candidate should solve quickly.

---

### Break down the requirements

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

Avoids the sentinel value problem of starting at 0 or negative infinity.

#### Step 2: Compare each element and update the running max

A single pass through the list, updating when a larger value is found.

---

### The solution

**Manual max scan without built-ins**

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

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

> **Interviewers Watch For**
>
> Not using `max()`, `sorted()`, or any built-in that hides the comparison logic. The point is to demonstrate you can write the loop.

> **Common Pitfall**
>
> Initializing `current_max = 0`. This fails for all-negative lists like `[-5, -3, -1]` where the answer is -1.

---

## Common follow-up questions

- How would you find the second largest value? _(Tests tracking two variables: the max and the runner-up.)_
- What if the list could be empty? _(Tests returning None or raising an appropriate exception.)_
- How would you find the max without using comparisons? _(Tests bit manipulation tricks, though this is typically theoretical.)_

## Related

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