Basic Counting Problems for Coding Interviews
111 basic Counting problems from real coding interviews, each with test cases you can run online. By difficulty they split into 111 basic, 0 intermediate and 0 advanced. The companies that ask them most often are Google, Amazon, Bloomberg, 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 Distinct Values (Basic)
- Count Vowels (Basic)
- Count Words (Basic)
- Count Negative Numbers (Basic)
- Count Odd Numbers in a Range (Basic)
- Count Asterisks Outside Bars (Basic)
- Unique Number of Occurrences (Basic)
- Count Pairs With a Target Sum (Basic)
- Count Numbers With Even Digits (Basic)
- Count Good Pairs (Basic)
- Rotated Array Occurrence Count (Basic)
- Count Pairs Divisible by K (Basic)
- Count Unique Binary Search Trees (Basic)
- Maximum Frequency After Increments (Basic)
- Count Downward Paths With Target Sum (Basic)
- Count Trailing Zeros in Factorial (Basic)
- Counting Bits (Basic)
- Count Paths With Target Sum (Basic)
- Count Distinct Islands Shapes (Basic)
- Count Range Sums (Basic)
- Count Subarrays With Median K (Basic)
- Boolean Parenthesization Count (Basic)
- Element Frequencies in a Linked List (Basic)
- Count Sorted Vowel Strings (Basic)
- Count Binary Substrings (Basic)
- Count the Number of Consistent Strings (Basic)
- Count Pairs of Similar Strings (Basic)
- Count Subtrees With Sum Equal to X (Basic)
- Lonely Pixel Count (Basic)
- Derangements Count (Basic)
- Count Anagram Groups (Basic)
- Count Prefixes of a Given String (Basic)
- Occurrences After Bigram (Basic)
- Count Items Matching a Rule (Basic)
- Sort Array by Increasing Frequency (Basic)
- Count Integers With Even Digit Sum (Basic)
- Count Total Colored Cells (Basic)
- Count Squares of Primes in Range (Basic)
- Count Abundant Numbers up to N (Basic)
- Count Balanced Bracket Prefixes (Basic)
- Count Elements With Smaller Left and Larger Right (Basic)
- Count Binary Strings Without Consecutive Ones (Basic)
- Collatz Steps Count (Basic)
- Message Route Node Count (Basic)
- Fridays the Thirteenth Count (Basic)
- Count Palindromic Times in Interval (Basic)
- Saddle Points Count (Basic)
- Count Distinct Rows in Matrix (Basic)
- Count Distinct Substrings of Length K (Basic)
- Count Overlapping Pattern Occurrences (Basic)
- Count Substrings With Equal Ends (Basic)
- First-Fit Memory Allocation Count (Basic)
- Linear Congruence Solution Count (Basic)
- Euclidean Algorithm Step Count (Basic)
- Count Elements Greater Than Average of Others (Basic)
- Count Pairs With Absolute Difference Equal to K (Basic)
- Count Permutation Cycles (Basic)
- Bubble Sort Swap Count (Basic)
- Selection Sort Swap Count (Basic)
- Descartes Sign Change Count (Basic)
- Component Count After Each Edge (Basic)
- Harshad Numbers Count (Basic)
- Automorphic Numbers Count (Basic)
- Alternating Bit Numbers Count (Basic)
- Queen Attack Squares Count (Basic)
- Knight Move Count From Square (Basic)
- Banknote Breakdown Count (Basic)
- Overdraft Event Count (Basic)
- Water Tank Overflow Count (Basic)
- Event Debounce Fire Count (Basic)
- Uppercase Run Count (Basic)
- Word Count Across Many Spaces (Basic)
- Camel Case Word Count (Basic)
- Palindromic Words Count (Basic)
- Strict Local Peaks Count (Basic)
- Strict Local Valleys Count (Basic)
- Sign Change Count (Basic)
- Running Record Highs Count (Basic)
- Zero Sum Prefix Count (Basic)
- Lucky Digits 4 and 7 Count (Basic)
Related
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.