DDSA Solutions

Counting

40 problems · 28 with full explanations

8 Easy12 Medium3 Hard
Counting problems enumerate valid configurations without explicitly generating them. Techniques: combinatorics (nCr), inclusion-exclusion, digit DP, and contribution of each element. In C#, use long to avoid overflow when multiplying counts.

How to practice

To practice Counting problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the counting pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.

Open the full study guide →

Start here (Easy + explained)

All Counting problems