Counting Problems for Coding Interviews
335 Counting problems from real coding interviews, each with test cases you can run online. By difficulty they split into 111 basic, 155 intermediate and 69 advanced. The companies that ask them most often are Google, Amazon, Microsoft, Meta.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Count Inversions (Advanced)
- Count Distinct Values (Basic)
- Count Vowels (Basic)
- Count and Say (Intermediate)
- Count Primes (Intermediate)
- Count Words (Basic)
- Counting Bits (Intermediate)
- Sort Characters by Frequency (Intermediate)
- Count Negative Numbers (Basic)
- Count Good Digit Strings (Intermediate)
- Count Substrings of Ones (Intermediate)
- Count Odd Numbers in a Range (Basic)
- Count Asterisks Outside Bars (Basic)
- Minimum Deletions for Unique Frequencies (Intermediate)
- Count Pairs With a Difference (Intermediate)
- Unique Number of Occurrences (Basic)
- Count Subarrays With K Odd Numbers (Intermediate)
- Count Pairs With a Target Sum (Basic)
- Count Pairs With Sum Below Target (Intermediate)
- Count Equal XOR Triplets (Advanced)
- Count Numbers With Even Digits (Basic)
- Count Good Pairs (Basic)
- Array Frequency Analysis (Intermediate)
- Rotated Array Occurrence Count (Basic)
- Minimum Coin Count With Limited Inventory (Intermediate)
- Count Palindromic Substrings (Intermediate)
- Count Pairs Divisible by K (Basic)
- Count Unique Binary Search Trees (Basic)
- Count Subarrays With Fixed Bounds (Intermediate)
- Count Subsets With Given XOR (Intermediate)
- Count Numbers With Unique Digits (Intermediate)
- Count Multiples in a Range (Intermediate)
- Count Smaller Values After Each Element (Intermediate)
- Maximum Frequency After Increments (Basic)
- Count Islands With Diagonal Adjacency (Advanced)
- Count Shortest Paths (Advanced)
- Count Complete Components (Intermediate)
- Count Walks With Exact Length (Intermediate)
- Count Downward Paths With Target Sum (Basic)
- Count Subsequence Occurrences (Advanced)
- Count Good Digit Strings (Intermediate)
- Count Trailing Zeros in Factorial (Basic)
- Counting Bits (Basic)
- Count Paths With Target Sum (Basic)
- Count Ways to Tile Board (Intermediate)
- Count Distinct Islands Shapes (Basic)
- Count Perfect Matchings (Intermediate)
- Count Divisible Numbers in Range (Intermediate)
- Count Range Sums (Basic)
- Count Substrings With Exactly K Distinct (Intermediate)
- Count Ways to Form Target From Columns (Intermediate)
- Count Subarrays With Sum Multiple of K (Intermediate)
- Count Subarrays With Median K (Basic)
- Count Range Frequency Queries (Intermediate)
- Count Negative Values in Sorted Matrix (Advanced)
- Longest Increasing Subsequence Count (Intermediate)
- Boolean Parenthesization Count (Basic)
- Count Good Nodes in Binary Tree (Intermediate)
- Element Frequencies in a Linked List (Basic)
- Count Complete Tree Nodes (Intermediate)
- Count Univalue Subtrees (Intermediate)
- Count Nodes Equal to Subtree Average (Intermediate)
- Count Full Binary Trees (Intermediate)
- Count Same-Label Nodes in Subtrees (Intermediate)
- Strongly Connected Components Count (Intermediate)
- Count Sub Islands (Intermediate)
- Count Paths in a DAG (Intermediate)
- Count Unreachable Pairs (Intermediate)
- Count Vowel Permutations (Intermediate)
- Count Square Submatrices (Intermediate)
- Student Attendance Record Count (Advanced)
- Arithmetic Subsequence Count (Advanced)
- Count Distinct Palindromic Subsequences (Advanced)
- Count Palindromic Partitions (Intermediate)
- Music Playlists Count (Advanced)
- Count Ways to Distribute Candies (Intermediate)
- Digit Sum in Range Count (Intermediate)
- Count Sorted Vowel Strings (Basic)
- Count Number of Texts (Intermediate)
- Count Ways to Build Good Strings (Intermediate)
Related
- Basic Counting problems
- Intermediate Counting problems
- Advanced Counting problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at counting problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run counting problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.