Overview
Scan the list once, tracking the smallest and largest values seen so far.
Analogy
Walking a street and noting the tallest and shortest buildings you pass.
Step-by-step
- Initialize min_val = max_val = list[0].
- For each element: update min_val if smaller, max_val if larger.
- Return both at the end.
- Alternatively use built-ins: min(lst), max(lst).
Visual
[3,1,4,1,5,9] → min=1, max=9 in one pass
Common mistakes
- Initializing min/max to 0 instead of the first element (fails for all-negatives).
- Calling min() and max() separately — two passes instead of one.
Practice questions
- Find min and max in a single pass without built-ins.
- Find the second largest element.