← Pointer Manipulation

Micro-Drill #2 — Find min and max

Pointer Manipulation Target: 10s

Single-pass min/max tracking is the basis for best-time-to-buy-stock and range queries.

mn, mx = min(a), max(a)

# Manual loop:
mn = mx = a[0]
for x in a[1:]:
    if x < mn: mn = x
    if x > mx: mx = x

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #1 Micro #3 →