← Sliding Window

Micro-Drill #102 — Track min price, max profit

Sliding Window Target: 10s

Single-pass tracking of running minimum and maximum profit. Classic greedy O(n) solution.

mn = float('inf')
mx = 0
for p in prices:
    mn = min(mn, p)
    mx = max(mx, p - mn)

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #101 Micro #103 →