Advanced Counting Problems for Coding Interviews
69 advanced Counting problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 0 intermediate and 69 advanced. The companies that ask them most often are Google, Amazon, Microsoft, Bloomberg.
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 Equal XOR Triplets (Advanced)
- Count Islands With Diagonal Adjacency (Advanced)
- Count Shortest Paths (Advanced)
- Count Subsequence Occurrences (Advanced)
- Count Negative Values in Sorted Matrix (Advanced)
- Student Attendance Record Count (Advanced)
- Arithmetic Subsequence Count (Advanced)
- Count Distinct Palindromic Subsequences (Advanced)
- Music Playlists Count (Advanced)
- Count Special Subsequences (Advanced)
- Word Search II Count (Advanced)
- Palindrome Pairs Count (Advanced)
- Count Unique Characters of All Substrings (Advanced)
- N-Queens Count (Advanced)
- Aho-Corasick Pattern Count (Advanced)
- Convex Hull Vertex Count (Advanced)
- Count Proper K-Colorings (Advanced)
- Count Spanning Trees (Advanced)
- Count Pairs of Nodes by Degree (Advanced)
- Count Possible Root Nodes (Advanced)
- Count Prime Paths in a Tree (Advanced)
- Count Visited Nodes in a Functional Graph (Advanced)
- Count the Number of Ideal Arrays (Advanced)
- Count Increasing Quadruplets (Advanced)
- Count All Possible Routes (Advanced)
- Count Palindromic Subsequences of Length 5 (Advanced)
- Count Beautiful Integers in Range (Advanced)
- Count Integers Divisible by Their Digit Sum (Advanced)
- Count Distinct Subsequences (Advanced)
- Count Distinct Substrings (Advanced)
- Maximum Frequency Stack (Advanced)
- Count Triplets With AND Zero (Advanced)
- Count Numbers With Digit Sum S in Range (Advanced)
- Count Square-Free Numbers up to N (Advanced)
- Count Linear Diophantine Solutions in a Box (Advanced)
- Domino and Tromino Tiling Count (Advanced)
- Count Coprime Pairs in Array (Advanced)
- Necklace Count Under Rotation (Advanced)
- Ranges Containing Another Range Count (Advanced)
- Count Hamiltonian Paths From First to Last (Advanced)
- Count Labeled Trees With Given Degrees (Advanced)
- Count Node Pairs at Distance K in Tree (Advanced)
- Count Descendants With Larger Value (Advanced)
- Count Subarrays With Bitwise AND Equal to K (Advanced)
- Count Numbers Up To N With K Set Bits (Advanced)
- Count Subsets With Zero AND (Advanced)
- Count Pairs With Zero AND (Advanced)
- Count Squares in Point Set (Advanced)
- Count Palindromic Rearrangements (Advanced)
- Capped Stars and Bars Count (Advanced)
- Bracelet Count With Reflections (Advanced)
- Count Sequences With GCD One (Advanced)
- Count Numbers With Exactly K Distinct Digits (Advanced)
- Count Numbers With Prime Digit Sum (Advanced)
- Count Numbers Divisible by M With Digit Sum S (Advanced)
- Count Numbers With Equal Even and Odd Digit Counts (Advanced)
- Count Independent Sets in Small Graph (Advanced)
- Count Seating Arrangements With Forbidden Neighbours (Advanced)
- Euler Totient Preimage Count (Advanced)
- Square Roots of Unity Modulo N Count (Advanced)
- Count Solutions of Two Congruences in Range (Advanced)
- Count Subarrays With Mex Equal to K (Advanced)
- Count Subarrays With Majority Element (Advanced)
- Pythagorean Triple Perimeter Count (Advanced)
- Count 132-Avoiding Permutations (Advanced)
- Stooge Sort Comparison Count (Advanced)
- Distinct Powers Count (Advanced)
- Surjections Count Modulo (Advanced)
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.