0PricingLogin
Competitive Programming Academy · Lesson

Min, Max, Sum & Running Totals

Aggregate a list in a single pass.

Aggregate in One Pass

Many problems just need a single number from an array. Python's built-ins do this aggregation in one fast pass over the list.

a = [4, 1, 7, 3]

Sum It Up

sum(a) adds every element and returns the total. It is C-fast, so prefer it over writing your own accumulation loop.

total = sum(a)  # 15

All lessons in this course

  1. Lists, Indexing & Slicing for CP
  2. Build Arrays Fast with Comprehensions
  3. Min, Max, Sum & Running Totals
  4. Find the Index, Not Just the Value
← Back to Competitive Programming Academy