Talentd
FleetCode
Make and follow sheets.Sign in

Counting Problems (203)

Problems tagged with Counting. Start with the easy ones, then move to medium and hard.

70 Easy110 Medium23 Hard

Learn these first

1
Array

Most counting problems start with arrays where you track element frequencies, pairs, or subarrays. Understanding array traversal and indexing makes it easier to implement counting strategies efficiently.

2
Hash Table

Hash tables are commonly used to store frequency counts of elements or track occurrences in O(1) average time. Many counting interview problems rely on hash maps to maintain dynamic counts.

3
Prefix Sum

Prefix sums help convert repeated counting of subarrays or ranges into constant-time queries. This technique is essential for problems that count subarrays with specific properties.

4
Combinatorics

Some counting problems require mathematical formulas such as combinations, permutations, or counting arrangements. Combinatorics helps compute counts without enumerating all possibilities.

5
Bit Manipulation

Bit manipulation techniques are useful for counting set bits, bit patterns, and subsets efficiently, which appears in many advanced counting interview questions.

TitleSolutionAcceptDifficultyTopics
Solution70.1%Medium
Array, Counting +1· 5 companies
Solution74.8%Easy
Counting, Hash Table +1· 3 companies
Solution80.4%Easy
Array, Counting +1· 4 companies
Solution74.9%Medium
Counting, Hash Table +1· 6 companies
Solution48.6%Medium
Array, Counting +2· 6 companies
Solution47.2%Hard
Array, Counting +2· 2 companies
Solution64.4%Easy
Array, Counting +1· 7 companies
Solution81.3%Medium
Array, Counting +1· 1 company
2013. Detect SquaresVideo
Solution53.0%Medium
Array, Counting +2· 4 companies
2029. Stone Game IXVideo
Solution57.6%Medium
Array, Counting +3· 1 company
Solution82.1%Easy
Array, Counting +2· 2 companies
Solution45.1%Medium
Counting, Prefix Sum +1· 1 company
Solution64.0%Medium
Array, Counting +1· 2 companies
Solution70.9%Medium
Counting, Greedy +3· 5 companies
Solution79.2%Easy
Array, Bit Manipulation +2· 5 companies
Solution72.4%Medium
Array, Counting +2· 4 companies
Solution63.5%Medium
Array, Counting +2· 2 companies
Solution68.8%Easy
Array, Counting +2· 2 companies
Solution71.2%Medium
Counting, Greedy +3· 1 company
Solution60.2%Medium
Array, Counting +2· 1 company
Solution76.0%Easy
Array, Counting +1· 1 company
2347. Best Poker HandVideo
Solution61.7%Easy
Array, Counting +1· 2 companies
Solution54.2%Medium
Array, Counting +2· 4 companies
Solution37.1%Medium
Counting, Greedy +2· 3 companies
Solution54.0%Easy
Array, Counting +1· 2 companies
Showing 51–100 of 203

More about Counting

Counting is a fundamental technique in data structures and algorithms that focuses on determining how many times something occurs. Instead of storing every element or combination, counting methods track frequencies, occurrences, or valid configurations efficiently. This approach often reduces time complexity and simplifies problems that would otherwise require heavy iteration or brute force.

In coding interviews, counting techniques appear in many forms—frequency tracking, counting valid pairs, counting subarrays, or counting combinational possibilities. Interviewers frequently expect candidates to recognize when a problem can be solved by maintaining counts rather than building complex structures. Many popular interview questions rely on counting ideas combined with tools like Hash Table frequency maps, prefix accumulations with Prefix Sum, or mathematical reasoning from Combinatorics.

Common counting patterns include:

  • Frequency counting using maps or arrays to track occurrences of elements.
  • Pair or triplet counting where the goal is to count valid combinations rather than list them.
  • Subarray counting using cumulative counts or prefix sums.
  • Bit-level counting using techniques from Bit Manipulation to count set bits or binary patterns.
  • Window-based counting where constraints are tracked dynamically with techniques like Sliding Window.

You should consider a counting approach when the problem asks "how many" rather than "which ones." Problems that involve duplicates, frequency comparisons, or combinational possibilities often become significantly easier when converted into counting problems.

Practicing counting problems helps you develop pattern recognition and efficient thinking—two skills that are critical for technical interviews. FleetCode provides ranging from beginner-friendly frequency tasks to advanced combinatorial challenges. By solving these problems, you'll learn how to transform brute-force enumeration into optimized counting strategies that scale well for large inputs.

Counting: common questions

What are Counting problems in DSA?

Counting problems in DSA focus on determining how many elements, pairs, subarrays, or configurations satisfy a given condition. Instead of listing all possibilities, efficient algorithms track frequencies or use mathematical reasoning to compute counts quickly.

Is Counting the same as Counting Sort?

No. Counting is a broader problem-solving technique used to compute frequencies or totals, while Counting Sort is a specific sorting algorithm that uses counts of elements to place them in sorted order.

What is the best way to learn Counting in DSA?

Start with simple frequency counting using arrays or hash maps, then move to pair counting and subarray counting problems. After that, practice problems involving prefix sums, combinatorics, and bit counting to handle more advanced scenarios.

Are Counting problems common in FAANG interviews?

Yes. Counting techniques frequently appear in FAANG-style problems, especially those involving subarrays, duplicates, frequency analysis, and combinatorial counting. Many medium-level interview questions rely on counting with hash maps or prefix sums.

What are common Counting patterns in coding interviews?

Common patterns include frequency maps, counting pairs or triplets, counting subarrays with prefix sums, combinational counting using formulas, and bit counting techniques for binary representations.