Find the largest integer in a list without using a built-in max function

Quick Overview

Return the largest integer in a list, or None when the list is empty, without calling a built-in maximum function. It tests basic array iteration and careful handling of edge cases such as an empty list or a list where every value is negative.

Find the largest integer in a list without using a built-in max function

Company: Worldpay

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a list of integers `nums`, return the maximum value in the list. If the list is empty, return `None`. You must implement this without using any built-in maximum utility, such as Python's `max`. ### Function Signature ```python def find_max(nums: list[int]) -> int | None: ``` ### Rules - Return `None` (Python's counterpart of `null`) when `nums` is empty. - Do not call `max` or any other built-in that returns the maximum directly. ### Constraints - `0 <= len(nums) <= 10^5` - `-10^9 <= nums[i] <= 10^9` ### Examples ```text Input: nums = [3,1,4,1,5,9,2,6] Output: 9 ``` The largest of the eight values is 9, at index 5. Every other value is 6 or less. ```text Input: nums = [] Output: None ``` An empty list has no maximum, so the function returns `None`. ```text Input: nums = [-7,-3,-12] Output: -3 ``` Every value is negative, and -3 is the largest of them.

Overview: Return the largest integer in a list, or None when the list is empty, without calling a built-in maximum function. It tests basic array iteration and careful handling of edge cases such as an empty list or a list where every value is negative.

Worldpay logo
Worldpay
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a list of integers nums, return the maximum value in the list. If the list is empty, return None.

You must implement this without using any built-in maximum utility, such as Python's max.

Function Signature

def find_max(nums: list[int]) -> int | None:

Rules

  • Return None (Python's counterpart of null ) when nums is empty.
  • Do not call max or any other built-in that returns the maximum directly.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9

Examples

Input: nums = [3,1,4,1,5,9,2,6]
Output: 9

The largest of the eight values is 9, at index 5. Every other value is 6 or less.

Input: nums = []
Output: None

An empty list has no maximum, so the function returns None.

Input: nums = [-7,-3,-12]
Output: -3

Every value is negative, and -3 is the largest of them.