~/problems

Problems

Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.

Counting

Combinatorics / inclusion-exclusion

Stars and bars, nCr identities, |A u B| = |A| + |B| - |A n B|.

Notes
  • Stars and bars: distributing n identical items into k boxes gives C(n + k - 1, k - 1) ways.
  • Permutations of a multiset: n! / (c1! c2! ...).
  • Inclusion-exclusion: |A ∪ B ∪ C| = Σ|A| - Σ|A∩B| + |A∩B∩C|. Used to count "at least one", or derangements (!n ≈ n!/e).
  • Pascal: C(n, k) = C(n-1, k-1) + C(n-1, k). Use it for small n or when there's no prime modulus.

4 problems

Advanced & competitive

Counting Combinatorics, inclusion-exclusion, Catalan numbers.

Combinatorics / inclusion-exclusion

esc