Counting Principles

The sum rule and product rule. When to add vs when to multiply. The foundation for all combinatorics.

43 lessons
139 min
Codeforces: 900-1300LeetCode: 1300-1600

Lessons

1. Intro

(The Goal)

2m

2. Why Counting Matters

(Algorithms need to know how many)

4m

3. The Sum Rule

(Add when choices are separate)

3m

4. Sum Rule Example

(Choosing a programming language)

4m

5. The Product Rule

(Multiply when choices are independent)

3m

6. Product Rule Example

(Building a username)

3m

7. When to Add vs Multiply

(The decision framework)

3m

8. Mixed Example

(Combining both rules)

3m

9. Problem - Count Passwords

(Simple product rule application)

2m

10. Password Count - Solution

(26^4 = 456,976)

3m

11. Password Variants

(Adding constraints)

4m

12. Counting Paths on Grids

(Classic DP problem)

4m

13. Counting Strings

(Character combinations)

4m

14. Counting with Restrictions

(Exclude certain cases)

4m

15. At Least One Constraint

(Common restriction pattern)

4m

16. Double Counting Principle

(Count the same set two ways)

4m

17. Pigeonhole Principle

(More items than containers)

3m

18. Pigeonhole Example

(Identical hash values)

3m

19. Inclusion-Exclusion Principle

(Count overlapping sets)

3m

20. Inclusion-Exclusion Example

(Students in clubs)

4m

21. Counting in Practice

(Real algorithm problems)

4m

22. What Comes Next

(Ordered counting)

4m

23. Overcounting and Correction

When simple rules fail

4m

24. Counting Subsets

The power of 2

3m

25. Counting Binary Strings

Direct application

3m

26. Counting with Forbidden Positions

Subtract what you cannot use

3m

27. Counting Divisors

Using prime factorization

3m

28. Problem - Climbing Stairs

Counting paths with steps

2m1 problems

29. Climbing Stairs - Insight

Recursive structure

3m

30. Climbing Stairs - Implementation

The pseudocode

4m1 problems

31. Problem - Unique Paths

(LeetCode 62 - Grid paths)

2m1 problems

32. Unique Paths - The Formula

(Sum of incoming paths)

3m

33. Unique Paths - Implementation

(2D DP table)

5m1 problems

34. Lessons from Unique Paths

(Grid counting principles)

2m

35. Problem - Unique Paths II

(LeetCode 63 - Obstacles)

2m1 problems

36. Unique Paths II - Handling Obstacles

(Setting blocked cells to 0)

3m

37. Unique Paths II - Implementation

(Modified DP with checks)

5m1 problems

38. Lessons from Unique Paths II

(Counting with constraints)

2m

39. Problem - Letter Combinations

(LeetCode 17 - Product rule)

2m1 problems

40. Letter Combinations - Counting First

(Product rule application)

4m

41. Letter Combinations - Implementation

(Backtracking generation)

5m1 problems

42. Lessons from Letter Combinations

(Product rule in practice)

2m

43. Section Recap

What we learned

2m

Ready to start learning?

Access all 43 lessons with interactive content and progress tracking.