Counting LeetCode Problems: All 126,
With Python Solutions

Every problem in this library that LeetCode tags Counting. 112 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
47
Medium
65
Hard
14
1 pattern

How Counting problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Counting problems — each one explains the approach, gives a Python template and states its complexity.

Eyes only

When the Counting problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Counting problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (47)

Easy problems
No.Problem
0169Majority Element
0383Ransom Note
0387First Unique Character in a String
0594Longest Harmonious Subsequence
0819Most Common Word
0884Uncommon Words from Two Sentences
0914X of a Kind in a Deck of Cards
1128Number of Equivalent Domino Pairs
1160Find Words That Can Be Formed by Characters
1189Maximum Number of Balloons
1221Split a String in Balanced Strings
1356Sort Integers by The Number of 1 Bits
1370Increasing Decreasing String
1394Find Lucky Integer in an Array
1512Number of Good Pairs
1603Design Parking System
1684Count the Number of Consistent Strings
1704Determine if String Halves Are Alike
1742Maximum Number of Balls in a Box
1748Sum of Unique Elements
1790Check if One String Swap Can Make Strings Equal
1854Maximum Population Year
1876Substrings of Size Three with Distinct Characters
1897Redistribute Characters to Make All Strings Equal
1941Check if All Characters Have Equal Number of Occurrences
2006Count Number of Pairs With Absolute Difference K
2053Kth Distinct String in an Array
2068Check Whether Two Strings are Almost Equivalent
2085Count Common Words With One Occurrence
2148Count Elements With Strictly Smaller and Greater Elements
2190Most Frequent Number Following Key In an Array
2206Divide Array Into Equal Pairs
2248Intersection of Multiple Arrays
2283Check if Number Has Equal Digit Count and Digit Value
2287Rearrange Characters to Make Target String
2341Maximum Number of Pairs in Array
2347Best Poker Hand
2351First Letter to Appear Twice
2404Most Frequent Even Element
2423Remove Letter To Equalize Frequency
2506Count Pairs Of Similar Strings
2529Maximum Count of Positive Integer and Negative Integer
2586Count the Number of Vowel Strings in Range
2748Number of Beautiful Pairs
2833Furthest Point From Origin
2960Count Tested Devices After Test Operations
1213Intersection of Three Sorted ArraysPremium

Medium (65)

Medium problems
No.Problem
0229Majority Element II
0299Bulls and Cows
0347Top K Frequent Elements
0451Sort Characters By Frequency
0621Task Scheduler
0692Top K Frequent Words
0767Reorganize String
0811Subdomain Visit Count
0869Reordered Power of 2
0900RLE Iterator
09233Sum With Multiplicity
0945Minimum Increment to Make Array Unique
1010Pairs of Songs With Total Durations Divisible by 60
1054Distant Barcodes
1079Letter Tile Possibilities
1090Largest Values From Labels
1267Count Servers that Communicate
1347Minimum Number of Steps to Make Two Strings Anagram
1366Rank Teams by Votes
1400Construct K Palindrome Strings
1419Minimum Number of Frogs Croaking
1481Least Number of Unique Integers after K Removals
1497Check If Array Pairs Are Divisible by k
1519Number of Nodes in the Sub-Tree With the Same Label
1657Determine if Two Strings Are Close
1726Tuple with Same Product
1737Change Minimum Characters to Satisfy One of Three Conditions
1775Equal Sum Arrays With Minimum Number of Operations
1781Sum of Beauty of All Substrings
1814Count Nice Pairs in an Array
2001Number of Pairs of Interchangeable Rectangles
2013Detect Squares
2023Number of Pairs of Strings With Concatenation Equal to Target
2029Stone Game IX
2048Next Greater Numerically Balanced Number
2131Longest Palindrome by Concatenating Two Letter Words
2150Find All Lonely Numbers in the Array
2170Minimum Operations to Make the Array Alternating
2182Construct String With Repeat Limit
2186Minimum Number of Steps to Make Two Strings Anagram II
2225Find Players With Zero or One Losses
2244Minimum Rounds to Complete All Tasks
2275Largest Combination With Bitwise AND Greater Than Zero
2284Sender With Largest Word Count
2364Count Number of Bad Pairs
2384Largest Palindromic Number
2442Count Number of Distinct Integers After Reverse Operations
2453Destroy Sequential Targets
2526Find Consecutive Integers from a Data Stream
2531Make Number of Distinct Characters Equal
2856Minimum Array Length After Pair Removals
2870Minimum Number of Operations to Make Array Empty
2981Find Longest Special Substring That Occurs Thrice I
2982Find Longest Special Substring That Occurs Thrice II
1198Find Smallest Common Element in All RowsPremium
1612Check If Two Expression Trees are EquivalentPremium
1940Longest Common Subsequence Between Sorted ArraysPremium
2067Number of Equal Count SubstringsPremium
2083Substrings That Begin and End With the Same LetterPremium
2168Unique Substrings With Equal Digit FrequencyPremium
2268Minimum Number of KeypressesPremium
2539Count the Number of Good SubsequencesPremium
2782Number of Unique CategoriesPremium
2950Number of Divisible SubstringsPremium
2955Number of Same-End SubstringsPremium

Hard (14)

Hard problems
No.Problem
0992Subarrays with K Different Integers
1255Maximum Score Words Formed by Letters
1782Count Pairs Of Nodes
1819Number of Different Subsequences GCDs
1857Largest Color Value in a Directed Graph
1994The Number of Good Subsets
2014Longest Subsequence Repeated k Times
2025Maximum Number of Ways to Partition an Array
2416Sum of Prefix Scores of Strings
2499Minimum Total Cost to Make Arrays Unequal
2514Count Anagrams
2547Minimum Cost to Split an Array
0358Rearrange String k Distance ApartPremium
1121Divide Array Into Increasing SequencesPremium