Programming Search⌘K

Taskintro

Find the largest element

Also called maximum of a list, max element, greatest element of a list, largest number in an array, argmax.

Find the largest item of a non-empty list of integers, and know what each language does for an empty list.

Task

Find the largest item of a list of integers. The function largest(items) returns the largest value. For example, largest([3, 1, 4, 1, 5]) is 5, and largest([-3, -1, -2]) is -1.

The list must have at least one item, because an empty list has no largest item. Each solution fails for an empty list: it raises an exception or it panics. The items are 32-bit signed integers.

Solutions

Language Find the largest item
Python max(items)
JavaScript, TypeScript a loop over the items
Java Arrays.stream(items).max().orElseThrow()
C# items.Max()
Go slices.Max(items)
Rust items.iter().max(), which gives an Option
C a loop that starts from items[0]
C++ std::ranges::max_element(items)
Bash a loop with ((x > best))
  • Python. "If multiple items are maximal, the function returns the first one encountered"1. Equal integers are the same value, so the result does not change.
  • JavaScript and TypeScript. Math.max(...items) gives each item as an argument. MDN says that "both spread (...) and apply will either fail or return the wrong result if the array has too many elements"2. The solution uses a loop, and it throws a RangeError for an empty array.
  • Java. The solution uses IntStream.max and orElseThrow. In the tests, an empty array throws NoSuchElementException.
  • C#. Max throws InvalidOperationException if the "source contains no elements"3.
  • Go. slices.Max "returns the maximal value in x. It panics if x is empty"4.
  • Rust. "If the iterator is empty, None is returned"5. The solution calls expect, so an empty slice panics.
  • C. The loop starts from items[0], not from 0. A start value of 0 gives 0 for a list of negative items.
  • C++. max_element returns an iterator. "If the target range is empty, returns last"6, so the solution tests for an empty span before it reads the item.
  • Bash. ((x > best)) compares the arguments as numbers.

Edge cases

The cases are in cases/basic.jsonl and cases/edge.jsonl.

  • single: the one item is the largest item.
  • all-negative and zero: the largest of -3, -1 and -2 is -1. A start value of 0 gives a wrong result for these lists.
  • first and last: the largest item can be at each end of the list.
  • duplicates and all-same: the largest value can occur more than once. The result is that value.
  • extremes and min-only: the items can be -2147483648 and 2147483647, the limits of a 32-bit signed integer.

The native tests of Python, JavaScript, TypeScript, Java, C#, Go, Rust and C++ also check that an empty list fails.

Pitfalls

  • Python max of an empty list raises ValueError. "If the iterable is empty and default is not provided, a ValueError is raised"1. Give default if the list can be empty:
items = []
try:
    max(items)
except ValueError as e:
    print(type(e).__name__)
print(max(items, default=None))
Output
ValueError
None
  • JavaScript Math.max with no arguments is -Infinity. Math.max returns "-Infinity if there are no parameters"2. In the example, a spread of 10,000,000 items throws a RangeError, and reduce works:
console.log(Math.max(...[]));
const big = Array.from({ length: 10_000_000 }, (_, i) => i);
try {
  console.log(Math.max(...big));
} catch (e) {
  console.log(e.name);
}
console.log(big.reduce((a, b) => Math.max(a, b), -Infinity));
Output
-Infinity
RangeError
9999999
  • Java start value 0 is wrong for negative items. In the example, the loop that starts from 0 gives 0 for {-3, -1, -2}. Also, Collections.max throws "NoSuchElementException - if the collection is empty"7:
import java.util.ArrayList;
import java.util.Collections;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    int[] items = {-3, -1, -2};
    int wrong = 0;
    for (int x : items) {
      if (x > wrong) {
        wrong = x;
      }
    }
    int best = items[0];
    for (int x : items) {
      if (x > best) {
        best = x;
      }
    }
    System.out.println(wrong + " " + best);
    try {
      Collections.max(new ArrayList<Integer>());
    } catch (NoSuchElementException e) {
      System.out.println("NoSuchElementException");
    }
  }
}
Output
0 -1
NoSuchElementException
  • C# Max of an empty array throws. In the example, Max of an empty int[] throws, and Max of an empty int?[] gives null:
int[] empty = [];
try
{
    Console.WriteLine(empty.Max());
}
catch (InvalidOperationException)
{
    Console.WriteLine("InvalidOperationException");
}
int?[] none = [];
Console.WriteLine(none.Max() is null);
Output
InvalidOperationException
True
  • Go slices.Max panics for an empty slice. If the slice can be empty, test its length first, and return a second value that tells if there is a result:
package main

import (
	"fmt"
	"slices"
)

func largest(items []int) (int, bool) {
	if len(items) == 0 {
		return 0, false
	}
	return slices.Max(items), true
}

func main() {
	fmt.Println(largest(nil))
	defer func() { fmt.Println("panic:", recover()) }()
	slices.Max([]int{})
}
Output
0 false
panic: slices.Max: empty list
  • Rust max gives the last of equal items. "If several elements are equally maximum, the last element is returned"5. In the example, max_by_key with the length gives "cc", not "bb". For f64 items, the example uses fold with f64::max:
fn main() {
    let empty: [i32; 0] = [];
    println!("{:?}", empty.iter().max());
    let words = ["bb", "a", "cc"];
    println!("{:?}", words.iter().max_by_key(|w| w.len()));
    let xs = [2.5_f64, -1.0, 7.0];
    println!("{}", xs.iter().copied().fold(f64::NEG_INFINITY, f64::max));
}
Output
None
Some("cc")
7
  • C n - 1 for an empty list. The count n is a size_t, which is unsigned. "Unsigned integer arithmetic is always performed modulo"8 a power of 2, so 0 - 1 is the largest size_t value. Test n first:
#include <stdio.h>

int main(void) {
    size_t n = 0;
    // n - 1 wraps around. A loop "i <= n - 1" runs for a very long time.
    printf("%zu\n", n - 1);
    // Test n first, and loop with i < n.
    if (n == 0) {
        printf("empty\n");
    }
    return 0;
}
Output
18446744073709551615
empty
  • C++ max_element of an empty range is the end. Do not dereference the end iterator. Also, "If there are multiple greatest elements, returns the iterator to the first one of them"6. In the example, the index of the first 9 is 1:
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    std::vector<int> empty;
    auto it = std::ranges::max_element(empty);
    std::cout << (it == empty.end()) << "\n";
    std::vector<int> v{3, 9, 9, 1};
    std::cout << std::ranges::distance(v.begin(), std::ranges::max_element(v)) << "\n";
}
Output
1
1
  • Bash [[ > ]] compares text. "string1 > string2 True if string1 sorts after string2 lexicographically"9. The text 10 sorts before the text 9. Use (( )) for numbers:
best=9
x=10
if [[ $x > $best ]]; then echo "text: 10 > 9"; else echo "text: 10 < 9"; fi
if ((x > best)); then echo "number: 10 > 9"; else echo "number: 10 < 9"; fi
Output
text: 10 < 9
number: 10 > 9

Code

The build runs the native tests of each language in a pinned toolchain.

largest.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-largest-element/.

def largest(items: list[int]) -> int:
    """Return the largest item of items. The list must not be empty."""
    # max raises ValueError for an empty list.
    return max(items)
test_largest.py 31 lines
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-largest-element/.

import pytest

from largest import largest

CASES = {
    "digits": ([3, 1, 4, 1, 5], 5),
    "middle": ([10, 20, 15], 20),
    "single": ([7], 7),
    "all-negative": ([-3, -1, -2], -1),
    "first": ([9, 2, 3], 9),
    "last": ([1, 2, 9], 9),
    "duplicates": ([5, 9, 9, 1], 9),
    "all-same": ([4, 4, 4], 4),
    "zero": ([-5, 0, -1], 0),
    "extremes": ([-2147483648, 2147483647, 0], 2147483647),
    "min-only": ([-2147483648], -2147483648),
}


@pytest.mark.parametrize("name", CASES)
def test_largest(name):
    items, want = CASES[name]
    assert largest(items) == want


def test_empty_raises():
    with pytest.raises(ValueError):
        largest([])
largest.cppI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#include "largest.hpp"

#include <algorithm>
#include <span>
#include <stdexcept>

int largest(std::span<const int> items) {
    if (items.empty()) {
        throw std::invalid_argument("largest: the span is empty");
    }
    return *std::ranges::max_element(items);
}
largest.hpp 10 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#pragma once

#include <span>

// largest returns the largest item. It throws std::invalid_argument if items
// is empty.
int largest(std::span<const int> items);
test_largest.cpp 43 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#include "largest.hpp"

#include <iostream>
#include <stdexcept>
#include <string_view>
#include <vector>

static int failures = 0;

static void check(std::string_view name, const std::vector<int> &items, int want) {
    if (largest(items) != want) {
        std::cerr << "case " << name << " failed\n";
        failures++;
    }
}

int main() {
    check("digits", std::vector<int>{3, 1, 4, 1, 5}, 5);
    check("middle", std::vector<int>{10, 20, 15}, 20);
    check("single", std::vector<int>{7}, 7);
    check("all-negative", std::vector<int>{-3, -1, -2}, -1);
    check("first", std::vector<int>{9, 2, 3}, 9);
    check("last", std::vector<int>{1, 2, 9}, 9);
    check("duplicates", std::vector<int>{5, 9, 9, 1}, 9);
    check("all-same", std::vector<int>{4, 4, 4}, 4);
    check("zero", std::vector<int>{-5, 0, -1}, 0);
    check("extremes", std::vector<int>{(-2147483647 - 1), 2147483647, 0}, 2147483647);
    check("min-only", std::vector<int>{(-2147483647 - 1)}, (-2147483647 - 1));
    try {
        largest(std::vector<int>{});
        std::cerr << "case empty: no exception\n";
        failures++;
    } catch (const std::invalid_argument &) {
    }
    if (failures > 0) {
        return 1;
    }
    std::cout << "all cases pass\n";
    return 0;
}
Largest.javaI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

import java.util.Arrays;

final class Largest {
  private Largest() {}

  /** Returns the largest item. It throws NoSuchElementException for an empty array. */
  static int largest(int[] items) {
    return Arrays.stream(items).max().orElseThrow();
  }
}
LargestTest.java 40 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.NoSuchElementException;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class LargestTest {
  static Stream<Arguments> cases() {
    return Stream.of(
        Arguments.of("digits", new int[] {3, 1, 4, 1, 5}, 5),
        Arguments.of("middle", new int[] {10, 20, 15}, 20),
        Arguments.of("single", new int[] {7}, 7),
        Arguments.of("all-negative", new int[] {-3, -1, -2}, -1),
        Arguments.of("first", new int[] {9, 2, 3}, 9),
        Arguments.of("last", new int[] {1, 2, 9}, 9),
        Arguments.of("duplicates", new int[] {5, 9, 9, 1}, 9),
        Arguments.of("all-same", new int[] {4, 4, 4}, 4),
        Arguments.of("zero", new int[] {-5, 0, -1}, 0),
        Arguments.of("extremes", new int[] {-2147483648, 2147483647, 0}, 2147483647),
        Arguments.of("min-only", new int[] {-2147483648}, -2147483648));
  }

  @ParameterizedTest(name = "{0}")
  @MethodSource("cases")
  void largest(String name, int[] items, int want) {
    assertEquals(want, Largest.largest(items));
  }

  @Test
  void emptyThrows() {
    assertThrows(NoSuchElementException.class, () -> Largest.largest(new int[0]));
  }
}
largest.cI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#include "largest.h"

int largest(const int *items, size_t n) {
    // Start from the first item, not from 0, so a list of negative items works.
    int best = items[0];
    for (size_t i = 1; i < n; i++) {
        if (items[i] > best) {
            best = items[i];
        }
    }
    return best;
}
largest.h 12 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#ifndef LARGEST_H
#define LARGEST_H

#include <stddef.h>

// largest returns the largest of items[0..n). n must be 1 or more.
int largest(const int *items, size_t n);

#endif
test_largest.c 40 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

#include "largest.h"

#include <stdbool.h>
#include <stdio.h>

static int failures = 0;

#define L(...) {__VA_ARGS__}

#define CHECK(name, n, given, want)                                      \
    do {                                                                 \
        const int g[] = given;                                           \
        int got = largest(g, n);                                             \
        if (got != (want)) {                                             \
            fprintf(stderr, "case %s: got %d, want %d\n", name, got, want); \
            failures++;                                                  \
        }                                                                \
    } while (0)

int main(void) {
    CHECK("digits", 5, L(3, 1, 4, 1, 5), 5);
    CHECK("middle", 3, L(10, 20, 15), 20);
    CHECK("single", 1, L(7), 7);
    CHECK("all-negative", 3, L(-3, -1, -2), -1);
    CHECK("first", 3, L(9, 2, 3), 9);
    CHECK("last", 3, L(1, 2, 9), 9);
    CHECK("duplicates", 4, L(5, 9, 9, 1), 9);
    CHECK("all-same", 3, L(4, 4, 4), 4);
    CHECK("zero", 3, L(-5, 0, -1), 0);
    CHECK("extremes", 3, L((-2147483647 - 1), 2147483647, 0), 2147483647);
    CHECK("min-only", 1, L((-2147483647 - 1)), (-2147483647 - 1));
    if (failures > 0) {
        return 1;
    }
    printf("all cases pass\n");
    return 0;
}
Largest.csI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

using System.Linq;

public static class Largest
{
    // Max throws InvalidOperationException for an empty array.
    public static int Find(int[] items) => items.Max();
}
LargestTests.cs 37 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

using System;
using Xunit;

public sealed class LargestTests
{
    public static TheoryData<string, int[], int> Cases => new()
    {
        { "digits", new int[] { 3, 1, 4, 1, 5 }, 5 },
        { "middle", new int[] { 10, 20, 15 }, 20 },
        { "single", new int[] { 7 }, 7 },
        { "all-negative", new int[] { -3, -1, -2 }, -1 },
        { "first", new int[] { 9, 2, 3 }, 9 },
        { "last", new int[] { 1, 2, 9 }, 9 },
        { "duplicates", new int[] { 5, 9, 9, 1 }, 9 },
        { "all-same", new int[] { 4, 4, 4 }, 4 },
        { "zero", new int[] { -5, 0, -1 }, 0 },
        { "extremes", new int[] { -2147483648, 2147483647, 0 }, 2147483647 },
        { "min-only", new int[] { -2147483648 }, -2147483648 },
    };

    [Theory]
    [MemberData(nameof(Cases))]
    public void Check(string name, int[] items, int want)
    {
        Assert.NotNull(name);
        Assert.Equal(want, Largest.Find(items));
    }

    [Fact]
    public void EmptyThrows()
    {
        Assert.Throws<InvalidOperationException>(() => Largest.Find(new int[0]));
    }
}
largest.jsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

/**
 * @param {number[]} items
 * @returns {number}
 */
export function largest(items) {
  if (items.length === 0) {
    throw new RangeError("largest: the array is empty");
  }
  // A loop, not Math.max(...items): the spread passes each item as an
  // argument, and a very long array can go past the limit.
  let best = items[0];
  for (const x of items) {
    if (x > best) {
      best = x;
    }
  }
  return best;
}
largest.test.js 31 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { largest } from "./largest.js";

const cases = [
  ["digits", [3, 1, 4, 1, 5], 5],
  ["middle", [10, 20, 15], 20],
  ["single", [7], 7],
  ["all-negative", [-3, -1, -2], -1],
  ["first", [9, 2, 3], 9],
  ["last", [1, 2, 9], 9],
  ["duplicates", [5, 9, 9, 1], 9],
  ["all-same", [4, 4, 4], 4],
  ["zero", [-5, 0, -1], 0],
  ["extremes", [-2147483648, 2147483647, 0], 2147483647],
  ["min-only", [-2147483648], -2147483648],
];

for (const [name, items, want] of cases) {
  test(name, () => {
    assert.deepEqual(largest(items), want);
  });
}

test("empty throws", () => {
  assert.throws(() => largest([]), RangeError);
});
largest.tsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

export function largest(items: readonly number[]): number {
  if (items.length === 0) {
    throw new RangeError("largest: the array is empty");
  }
  // A loop, not Math.max(...items): the spread passes each item as an
  // argument, and a very long array can go past the limit.
  let best = items[0];
  for (const x of items) {
    if (x > best) {
      best = x;
    }
  }
  return best;
}
largest.test.ts 31 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

import assert from "node:assert/strict";
import { test } from "node:test";

import { largest } from "./largest.ts";

const cases: [string, number[], number][] = [
  ["digits", [3, 1, 4, 1, 5], 5],
  ["middle", [10, 20, 15], 20],
  ["single", [7], 7],
  ["all-negative", [-3, -1, -2], -1],
  ["first", [9, 2, 3], 9],
  ["last", [1, 2, 9], 9],
  ["duplicates", [5, 9, 9, 1], 9],
  ["all-same", [4, 4, 4], 4],
  ["zero", [-5, 0, -1], 0],
  ["extremes", [-2147483648, 2147483647, 0], 2147483647],
  ["min-only", [-2147483648], -2147483648],
];

for (const [name, items, want] of cases) {
  test(name, () => {
    assert.deepEqual(largest(items), want);
  });
}

test("empty throws", () => {
  assert.throws(() => largest([]), RangeError);
});
largest.goI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

// Package largest finds the largest item of a slice.
package largest

import "slices"

// Largest returns the largest item. It panics if items is empty.
func Largest(items []int) int {
	return slices.Max(items)
}
largest_test.go 41 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

package largest

import "testing"

var cases = []struct {
	name  string
	items []int
	want  int
}{
	{"digits", []int{3, 1, 4, 1, 5}, 5},
	{"middle", []int{10, 20, 15}, 20},
	{"single", []int{7}, 7},
	{"all-negative", []int{-3, -1, -2}, -1},
	{"first", []int{9, 2, 3}, 9},
	{"last", []int{1, 2, 9}, 9},
	{"duplicates", []int{5, 9, 9, 1}, 9},
	{"all-same", []int{4, 4, 4}, 4},
	{"zero", []int{-5, 0, -1}, 0},
	{"extremes", []int{-2147483648, 2147483647, 0}, 2147483647},
	{"min-only", []int{-2147483648}, -2147483648},
}

func TestLargest(t *testing.T) {
	for _, c := range cases {
		if got := Largest(c.items); got != c.want {
			t.Errorf("%s: got %v, want %v", c.name, got, c.want)
		}
	}
}

func TestEmptyPanics(t *testing.T) {
	defer func() {
		if recover() == nil {
			t.Error("no panic for an empty slice")
		}
	}()
	Largest(nil)
}
largest.rsI0RawGitHub
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

/// Returns the largest item. It panics if `items` is empty.
pub fn largest(items: &[i32]) -> i32 {
    // max gives None for an empty slice.
    *items.iter().max().expect("largest: the slice is empty")
}
tests/largest_test.rs 30 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/find-the-largest-element/.

use algo_find_the_largest_element::largest;

#[test]
fn cases() {
    let cases: &[(&str, &[i32], i32)] = &[
        ("digits", &[3, 1, 4, 1, 5], 5),
        ("middle", &[10, 20, 15], 20),
        ("single", &[7], 7),
        ("all-negative", &[-3, -1, -2], -1),
        ("first", &[9, 2, 3], 9),
        ("last", &[1, 2, 9], 9),
        ("duplicates", &[5, 9, 9, 1], 9),
        ("all-same", &[4, 4, 4], 4),
        ("zero", &[-5, 0, -1], 0),
        ("extremes", &[-2147483648, 2147483647, 0], 2147483647),
        ("min-only", &[-2147483648], -2147483648),
    ];
    for &(name, items, want) in cases {
        assert_eq!(largest(items), want, "{name}");
    }
}

#[test]
#[should_panic]
fn empty_panics() {
    largest(&[]);
}
largest.shI0RawGitHub
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-largest-element/.

# largest ITEM...
# Prints the largest of the integer arguments. Give 1 argument or more.
largest() {
  local best=$1 x
  for x in "$@"; do
    # (( )) compares numbers. [[ $x > $best ]] would compare text.
    if ((x > best)); then
      best=$x
    fi
  done
  printf '%s\n' "$best"
}
test_largest.bats 37 lines
#!/usr/bin/env bats
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/find-the-largest-element/.

bats_require_minimum_version 1.5.0

setup() {
  source "$BATS_TEST_DIRNAME/largest.sh"
}

lines() { # lines ITEM...: prints each item on a line, and nothing for no items
  if (($# > 0)); then printf '%s\n' "$@"; fi
}

check() { # check FUNCTION GIVEN... -- WANT...
  local fn=$1 got want
  shift
  local -a given=()
  while [ "$1" != -- ]; do given+=("$1"); shift; done
  shift
  # The x keeps the trailing newlines, which $(...) removes.
  got=$("$fn" "${given[@]}"; printf x)
  want=$(lines "$@"; printf x)
  [ "$got" = "$want" ] || { printf 'got:  %q\nwant: %q\n' "$got" "$want"; return 1; }
}

@test "digits" { check largest 3 1 4 1 5 -- 5; }
@test "middle" { check largest 10 20 15 -- 20; }
@test "single" { check largest 7 -- 7; }
@test "all-negative" { check largest -3 -1 -2 -- -1; }
@test "first" { check largest 9 2 3 -- 9; }
@test "last" { check largest 1 2 9 -- 9; }
@test "duplicates" { check largest 5 9 9 1 -- 9; }
@test "all-same" { check largest 4 4 4 -- 4; }
@test "zero" { check largest -5 0 -1 -- 0; }
@test "extremes" { check largest -2147483648 2147483647 0 -- 2147483647; }
@test "min-only" { check largest -2147483648 -- -2147483648; }

References

  1. The Python Standard Library, Built-in Functions, max()
  2. MDN Web Docs, Math.max(), Return value, Getting the maximum element of an array
  3. .NET API reference, Enumerable.Max method, Exceptions
  4. Go standard library, package slices, Max
  5. Rust standard library, trait Iterator, max, max_by_key
  6. cppreference.com, std::max_element, Return value
  7. Java SE 25 API, Class Collections, max(Collection)
  8. cppreference.com, C arithmetic operators, Overflows
  9. Bash Reference Manual, 6.4 Bash Conditional Expressions

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (bash)I0 not checked yet
  • the tests did not run in this build
Code (c)I0 not checked yet
  • the tests did not run in this build
Code (cpp)I0 not checked yet
  • the tests did not run in this build
Code (csharp)I0 not checked yet
  • the tests did not run in this build
Code (go)I0 not checked yet
  • the tests did not run in this build
Code (java)I0 not checked yet
  • the tests did not run in this build
Code (javascript)I0 not checked yet
  • the tests did not run in this build
Code (python)I0 not checked yet
  • the tests did not run in this build
Code (rust)I0 not checked yet
  • the tests did not run in this build
Code (typescript)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • a history with a source