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.
Start here (Easy + explained)
All Counting problems
- 299.Bulls and CowsUnknown
- 594.Longest Harmonious SubsequenceEasy
- 726.Number of AtomsHard
- 869.Reordered Power of 2Medium
- 884.Uncommon Words from Two SentencesEasy
- 1079.Letter Tile PossibilitiesMedium
- 1128.Number of Equivalent Domino PairsEasy
- 1267.Count Servers that CommunicateMedium
- 1399.Count Largest GroupUnknown
- 1400.Construct K Palindrome StringsUnknown
- 1636.Sort Array by Increasing FrequencyUnknown
- 1790.Check if One String Swap Can Make Strings EqualEasy
- 1857.Largest Color Value in a Directed GraphHard
- 1922.Count Good NumbersUnknown
- 2131.Longest Palindrome by Concatenating Two Letter WordsMedium
- 2176.Count Equal and Divisible Pairs in an ArrayUnknown
- 2182.Construct String With Repeat LimitMedium
- 2206.Divide Array Into Equal PairsEasy
- 2210.Count Hills and Valleys in an ArrayUnknown
- 2225.Find Players With Zero or One LossesMedium
- 2275.Largest Combination With Bitwise AND Greater Than ZeroMedium
- 2416.Sum of Prefix Scores of StringsHard
- 2529.Maximum Count of Positive Integer and Negative IntegerEasy
- 2799.Count Complete Subarrays in an ArrayMedium
- 2930.Number of Strings Which Can Be Rearranged to Contain SubstringMedium
- 3005.Count Elements With Maximum FrequencyEasy
- 3016.Minimum Number of Pushes to Type Word IIMedium
- 3223.Minimum Length of String After OperationsUnknown
- 3272.Find the Count of Good IntegersUnknown
- 3330.Find the Original Typed String IEasy
- 3335.Total Characters in String After Transformations IMedium
- 3337.Total Characters in String After Transformations IIUnknown
- 3343.Count Number of Balanced PermutationsUnknown
- 3405.Count the Number of Arrays with K Matching Adjacent ElementsUnknown
- 3442.Maximum Difference Between Even and Odd Frequency IMedium
- 3541.Find Most Frequent Vowel and ConsonantUnknown
- 3577.Count the Number of Computer Unlocking PermutationsUnknown
- 3583.Count Special TripletsUnknown
- 3623.Count Number of Trapezoids IUnknown
- 3625.Count Number of Trapezoids IIUnknown