Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Find Maximum Value

Find the largest number in a list of integers. Returns None for an empty list.

Python practice6 minLoops & IterationBeginnerLast updated March 15, 2026

Problem statement

Write a function find_max(nums) that takes a list of integers nums and returns the maximum value in the list. If nums is empty, return None. Do not use the built-in max() function; iterate through the list and track the largest value manually.

Task

Practice iterating through a list to identify the maximum value and handle empty inputs.

Examples

Basic example

Input

find_max([3, 1, 4, 2])

Output

4

Among the numbers 3, 1, 4, 2 the largest is 4.

Input format

A single list of integers, e.g. [1, 2, 3].

Output format

An integer (the maximum) or None for an empty list.

Constraints

You must not use the built-in max() or sorted(). Aim for O(n) time and O(1) extra space.

Samples

Sample 1

Input

find_max([-5, -2, -3])

Output

-2

The maximum among the negatives is -2.