Lessons 1–5 · About 60 min per lesson
Complexity, numeric range and debugging
Use data size to judge feasibility, then verify numeric types.
Lesson breakdown
- Lesson 1
Estimate the work of single and nested loops.
- Lesson 2
Compare growth in O(n), O(n log n) and O(n²).
- Lesson 3
Store large results in long long and widen an operand before multiplying.
- Lesson 4
Track down out-of-bounds access, uninitialised values and empty-container access.
- Lesson 5
Compare behaviour on generated small and large inputs.
Worked example
For n=200000, compare one full scan with examining every distinct index pair.
How to solve it
A scan takes 200000 steps, versus n(n−1)/2 = 19,999,900,000 pairs. Use 1LL * n * (n - 1) / 2 to count the pairs.
Assignment
Write a pair-counting function and explain the complexity of enumeration and the formula.
Check your result
n=1 → 0; n=5 → 10; n=200000 → 19999900000.