Skip to content

Smallest and largest

Smallest and largest

Find both ends of a list in a single pass.

Keep two values at once, both starting as the first item. Check each number against both: it may replace the smallest, the largest, or neither.

Log in or create account

IGCSE, A-Level & AP