LeetCodechevron_rightCategorieschevron_rightcounting
pin

counting

149 problems
Easy: 56Medium: 77Hard: 16

counting is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.

Interview Signal

Frequently tests problem modeling, edge handling, and verbal clarity.

Common Pitfall

Template-only answers break under follow-up questioning.

Practice Strategy

Practice in 3-5 problem rounds and always review complexity alternatives.

Recommended Progression

#TitleDifficulty
169

Majority Element

Find the majority element in an array, where the element appears more than n/2 times, using efficient algorithms.

Easy
229

Majority Element II

Identify all elements in an integer array appearing more than ⌊ n/3 ⌋ times using efficient array scanning and hash coun…

Medium
299

Bulls and Cows

Solve the Bulls and Cows problem using hash tables and string manipulation to track exact and misplaced digits.

Medium
347

Top K Frequent Elements

Find the k most frequent elements from an array using efficient algorithms like hashing and sorting.

Medium
383

Ransom Note

Determine if a ransom note can be constructed from a magazine's letters using hash tables and string counting techniques…

Easy
387

First Unique Character in a String

Find the index of the first non-repeating character in a string using efficient queue-driven state processing.

Easy
451

Sort Characters By Frequency

Sort Characters By Frequency requires counting characters efficiently and rearranging a string in descending frequency o…

Medium
594

Longest Harmonious Subsequence

Find the length of the longest harmonious subsequence in an integer array using array scanning and hash-based frequency …

Easy
621

Task Scheduler

Task Scheduler is solved by counting task frequencies and computing how cooldown gaps force idle slots around the most f…

Medium
692

Top K Frequent Words

Solve Top K Frequent Words by counting each word, then ordering ties alphabetically so frequency wins before lexicograph…

Medium
767

Reorganize String

Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.

Medium
811

Subdomain Visit Count

The Subdomain Visit Count problem requires counting the visits to all subdomains of a given domain from a list of count-…

Medium
819

Most Common Word

Find the most frequent non-banned word in a paragraph, excluding punctuation, using an efficient array scan and hash tab…

Easy
869

Reordered Power of 2

Determine if a number's digits can be rearranged to form a power of two using counting and hash-based checks.

Medium
884

Uncommon Words from Two Sentences

Find uncommon words from two sentences by counting word frequencies using hash tables.

Easy
900

RLE Iterator

Design an efficient iterator for a run-length encoded array, handling large counts and sequential access correctly every…

Medium
914

X of a Kind in a Deck of Cards

Solve the problem of determining if a deck can be partitioned into groups with equal occurrences of card values.

Easy
923

3Sum With Multiplicity

Count all unique triplets in an integer array whose sum equals the target, handling multiplicity efficiently using hashi…

Medium
945

Minimum Increment to Make Array Unique

This problem challenges you to find the minimum moves to make all elements in an array unique by incrementing elements.

Medium
992

Subarrays with K Different Integers

Find subarrays with exactly k distinct integers in an integer array using sliding window and hash lookup techniques.

Hard
1010

Pairs of Songs With Total Durations Divisible by 60

Calculate the number of song pairs whose total durations sum to a multiple of 60 using array scanning and hash lookups.

Medium
1054

Distant Barcodes

Rearrange barcodes in an array so that no two adjacent elements are equal, using a greedy approach and hash table for ef…

Medium
1079

Letter Tile Possibilities

Compute all unique non-empty sequences from given letter tiles using backtracking search with pruning efficiently.

Medium
1090

Largest Values From Labels

Maximize the sum of selected item values while respecting label use limits using array scanning and hash tracking.

Medium
1128

Number of Equivalent Domino Pairs

Count all pairs of dominoes that are equivalent by scanning the array and using a hash table for fast lookup.

Easy
1160

Find Words That Can Be Formed by Characters

Compute the total length of words that can be fully constructed from given characters using array scanning and hash mapp…

Easy
1189

Maximum Number of Balloons

Find the maximum number of times the word 'balloon' can be formed from characters of the given string.

Easy
1221

Split a String in Balanced Strings

Split a string into the maximum number of balanced substrings where each substring has an equal number of 'L' and 'R'.

Easy
1267

Count Servers that Communicate

Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…

Medium
1347

Minimum Number of Steps to Make Two Strings Anagram

Calculate the minimum steps to transform one string into an anagram of another using character replacements efficiently.

Medium
1356

Sort Integers by The Number of 1 Bits

Sort an array of integers by the number of 1's in their binary representation and then by their value in case of ties.

Easy
1366

Rank Teams by Votes

Rank Teams by Votes requires counting position-based votes and resolving ties with array scanning and hash lookup techni…

Medium
1370

Increasing Decreasing String

Reorder the string based on a specific algorithm using hash tables and string manipulation.

Easy
1394

Find Lucky Integer in an Array

Identify the largest lucky integer in an array by counting frequencies and comparing values with their occurrences effic…

Easy
1400

Construct K Palindrome Strings

Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…

Medium
1419

Minimum Number of Frogs Croaking

Determine the minimum number of frogs required to sequentially produce all croaks in a mixed frog croak string efficient…

Medium
1481

Least Number of Unique Integers after K Removals

Find the least number of unique integers after removing exactly k elements from an array using efficient frequency count…

Medium
1497

Check If Array Pairs Are Divisible by k

Check if array pairs are divisible by k by pairing elements whose sums are divisible by k using array scanning and hash …

Medium
1512

Number of Good Pairs

Count all index pairs in an array where elements match and the first index is smaller, using hash-based scanning efficie…

Easy
1519

Number of Nodes in the Sub-Tree With the Same Label

Compute the number of nodes in each subtree sharing the same label using DFS with hash table aggregation efficiently.

Medium
1603

Design Parking System

Implement a class to manage a parking lot with fixed slots for big, medium, and small cars, tracking occupancy efficient…

Easy
1657

Determine if Two Strings Are Close

Check if two strings can transform into each other using letter swaps and frequency reorganizations, leveraging hash tab…

Medium
1684

Count the Number of Consistent Strings

Count the number of strings fully composed of allowed characters using array scanning and hash lookup for efficiency.

Easy
1704

Determine if String Halves Are Alike

Check if two halves of a string contain the same number of vowels using a character counting approach efficiently.

Easy
1726

Tuple with Same Product

Given an array of distinct integers, return the number of tuples where the product of two pairs is the same.

Medium
1737

Change Minimum Characters to Satisfy One of Three Conditions

This problem asks for the minimum operations to change two strings so that one of three conditions is met.

Medium
1742

Maximum Number of Balls in a Box

The problem asks you to find the box with the maximum number of balls based on the sum of digits of ball numbers.

Easy
1748

Sum of Unique Elements

Given an array, find the sum of all its unique elements by identifying those that appear only once.

Easy
1775

Equal Sum Arrays With Minimum Number of Operations

Solve the problem of balancing the sums of two integer arrays with minimal operations, using array scanning and hash loo…

Medium
1781

Sum of Beauty of All Substrings

Calculate the total beauty of all substrings by counting character frequencies and computing frequency differences effic…

Medium
1782

Count Pairs Of Nodes

Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.

Hard
1790

Check if One String Swap Can Make Strings Equal

Check if one string swap can make two equal strings using hash table and string counting methods.

Easy
1814

Count Nice Pairs in an Array

Count Nice Pairs in an Array requires efficiently pairing numbers where nums[i] + rev(nums[j]) equals nums[j] + rev(nums…

Medium
1819

Number of Different Subsequences GCDs

Given an array of positive integers, find the number of different subsequences' GCDs.

Hard
1854

Maximum Population Year

Find the earliest year with the highest population using an array plus counting approach.

Easy
1857

Largest Color Value in a Directed Graph

Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…

Hard
1876

Substrings of Size Three with Distinct Characters

Count all substrings of length three in a string where each character is unique using sliding window techniques efficien…

Easy
1897

Redistribute Characters to Make All Strings Equal

Determine if you can redistribute characters among strings so that all strings become identical using a counting approac…

Easy
1941

Check if All Characters Have Equal Number of Occurrences

Check if a string has characters with equal occurrences using hash tables and string manipulation techniques.

Easy
1994

The Number of Good Subsets

Find the number of good subsets in an integer array, where each subset's product is the product of distinct primes.

Hard
2001

Number of Pairs of Interchangeable Rectangles

Count all pairs of rectangles that share the exact width-to-height ratio using efficient array scanning and hash lookup.

Medium
2006

Count Number of Pairs With Absolute Difference K

Find how many pairs (i, j) with i < j satisfy |nums[i] - nums[j]| == k using array scanning and hash lookup.

Easy
2013

Detect Squares

Detect Squares requires tracking points on a 2D plane to quickly count all possible axis-aligned squares using efficient…

Medium
2014

Longest Subsequence Repeated k Times

Find the longest subsequence repeated k times in a string using backtracking search with pruning.

Hard
2023

Number of Pairs of Strings With Concatenation Equal to Target

Count all unique index pairs in a string array whose concatenation exactly matches the given target string using efficie…

Medium
2025

Maximum Number of Ways to Partition an Array

Determine the maximum number of ways to split an array into equal sums using at most one element change, leveraging pref…

Hard
2029

Stone Game IX

In the Stone Game IX problem, Alice and Bob take turns removing stones, and Alice wins if the sum of removed stones is d…

Medium
2048

Next Greater Numerically Balanced Number

Find the smallest numerically balanced number greater than a given integer using backtracking search and pruning.

Medium
2053

Kth Distinct String in an Array

Find the kth distinct string in an array by identifying strings that appear only once, using efficient array scanning an…

Easy
2068

Check Whether Two Strings are Almost Equivalent

Solve Check Whether Two Strings are Almost Equivalent by counting letters and rejecting any character whose frequency ga…

Easy
2085

Count Common Words With One Occurrence

Learn how to efficiently count strings appearing exactly once in both arrays using array scanning and hash lookup patter…

Easy
2131

Longest Palindrome by Concatenating Two Letter Words

Find the maximum-length palindrome by combining two-letter words using array scanning and hash table lookups efficiently…

Medium
2148

Count Elements With Strictly Smaller and Greater Elements

Count elements in an array that have both strictly smaller and strictly greater numbers using array sorting efficiently.

Easy
2150

Find All Lonely Numbers in the Array

Find lonely numbers in an array where each lonely number appears once and has no adjacent values.

Medium
2170

Minimum Operations to Make the Array Alternating

Given an array, calculate the minimum number of operations needed to make it alternating.

Medium
2182

Construct String With Repeat Limit

Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …

Medium
2186

Minimum Number of Steps to Make Two Strings Anagram II

Compute the fewest character insertions needed to turn two strings into anagrams using hash table frequency counts effic…

Medium
2190

Most Frequent Number Following Key In an Array

Scan the array once, count which value appears right after the key, and return the uniquely most frequent follower.

Easy
2206

Divide Array Into Equal Pairs

Determine if an array of 2n integers can be partitioned into n pairs where each pair contains identical elements using h…

Easy
2225

Find Players With Zero or One Losses

Identify players with zero or one losses by efficiently scanning arrays and counting losses using hash lookups for accur…

Medium
2244

Minimum Rounds to Complete All Tasks

The problem requires finding the minimum rounds to complete tasks, focusing on greedy algorithms and hash table lookups.

Medium
2248

Intersection of Multiple Arrays

Find integers that are common across all arrays in a given list of arrays.

Easy
2275

Largest Combination With Bitwise AND Greater Than Zero

Find the largest group of integers in an array whose bitwise AND is greater than zero using array scanning and hash look…

Medium
2283

Check if Number Has Equal Digit Count and Digit Value

Determine if a number's digits correspond to their counts in the string representation.

Easy
2284

Sender With Largest Word Count

Find the sender with the largest total word count by scanning messages and tallying counts using a hash table efficientl…

Medium
2287

Rearrange Characters to Make Target String

Calculate the maximum copies of a target string from letters in s using frequency counting and hash tables efficiently.

Easy
2341

Maximum Number of Pairs in Array

Given an array, count how many pairs can be formed and how many leftovers remain after pairing.

Easy
2347

Best Poker Hand

Determine the strongest poker hand from five cards using array scanning and hash table counting techniques efficiently.

Easy
2351

First Letter to Appear Twice

Find the first letter that repeats in a string using hash table tracking and early detection for efficiency.

Easy
2364

Count Number of Bad Pairs

Count the number of bad pairs in an array where the difference between indices and values does not match.

Medium
2384

Largest Palindromic Number

Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.

Medium
2404

Most Frequent Even Element

Identify the most frequent even element in an array using counting and hash lookup, handling ties by choosing the smalle…

Easy
2416

Sum of Prefix Scores of Strings

The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …

Hard
2423

Remove Letter To Equalize Frequency

Determine if removing a single letter from a string can make all remaining letters have identical frequency efficiently.

Easy
2442

Count Number of Distinct Integers After Reverse Operations

This problem requires counting distinct integers after performing reverse operations on each integer in an array.

Medium
2453

Destroy Sequential Targets

Find the minimum seed value to destroy the most targets on a number line, using array scanning and hash lookup.

Medium
2499

Minimum Total Cost to Make Arrays Unequal

Calculate the minimum cost to rearrange nums1 so that no element matches nums2 using optimal swaps and hash counting.

Hard
2506

Count Pairs Of Similar Strings

Count similar string pairs by converting each word into a character-set signature and counting matching signatures effic…

Easy
2514

Count Anagrams

Learn to count distinct anagrams for a multi-word string using hash tables, math, and combinatorics efficiently.

Hard
2526

Find Consecutive Integers from a Data Stream

Design a data stream checker to identify consecutive integers from a stream, focusing on handling state transitions effi…

Medium
2529

Maximum Count of Positive Integer and Negative Integer

Compute the maximum count between positive and negative integers in a sorted array using efficient binary search countin…

Easy
2531

Make Number of Distinct Characters Equal

Determine if a single swap can equalize distinct character counts between two strings using hash tables for tracking fre…

Medium
2547

Minimum Cost to Split an Array

Minimize the cost of splitting an array into k subarrays by calculating importance values and applying dynamic programmi…

Hard
2586

Count the Number of Vowel Strings in Range

Count the Number of Vowel Strings in Range asks to count vowel strings in a subarray of a given word list.

Easy
2748

Number of Beautiful Pairs

Count all index pairs in an array where the first digit of one number and last digit of another are coprime efficiently.

Easy
2833

Furthest Point From Origin

Determine the maximum distance from origin using string moves and counting underscores optimally for efficient calculati…

Easy
2856

Minimum Array Length After Pair Removals

This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.

Medium
2870

Minimum Number of Operations to Make Array Empty

Minimize the number of operations to make an array empty by leveraging array scanning and hash lookup.

Medium
2960

Count Tested Devices After Test Operations

Simulate testing devices based on battery percentages to determine how many pass the test operations in sequence.

Easy
2981

Find Longest Special Substring That Occurs Thrice I

Find the longest special substring in a string that appears at least three times, or return -1 if no such substring exis…

Medium
2982

Find Longest Special Substring That Occurs Thrice II

Find the longest special substring that occurs at least three times in a given string using binary search and hash table…

Medium
3005

Count Elements With Maximum Frequency

Count Elements With Maximum Frequency is solved by counting each value, tracking the highest count, and summing matching…

Easy
3016

Minimum Number of Pushes to Type Word II

Given a word, find the minimum number of pushes to type it on a remapped keypad using a greedy approach.

Medium
3035

Maximum Palindromes After Operations

The problem focuses on maximizing the number of palindromes that can be formed from a given list of words through specif…

Medium
3039

Apply Operations to Make String Empty

Learn how to systematically apply operations on a string using array scanning and hash lookups to reduce it efficiently.

Medium
3044

Most Frequent Prime

Find the most frequent prime over 10 from numbers generated by scanning a 2D matrix in all straight directions efficient…

Medium
3046

Split the Array

Determine if an even-length array can be split into two parts with all distinct elements using hash lookup scanning.

Easy
3071

Minimum Operations to Write the Letter Y on a Grid

Find the minimum number of operations to write the letter Y on a grid by altering cell values.

Medium
3081

Replace Question Marks in String to Minimize Its Value

Minimize the cost of a string with '?' characters by replacing them with letters in lexicographical order while minimizi…

Medium
3084

Count Substrings Starting and Ending with Given Character

Given a string and a character, find the total number of substrings that start and end with that character.

Medium
3085

Minimum Deletions to Make String K-Special

Minimize deletions to make a string k-special by adjusting character frequencies.

Medium
3128

Right Triangles

Count all possible right triangles in a 2D boolean grid using array scanning and hash lookup for efficiency.

Medium
3137

Minimum Number of Operations to Make Word K-Periodic

The problem requires calculating the minimum number of operations to make a string k-periodic using specific substring r…

Medium
3138

Minimum Length of Anagram Concatenation

The problem asks to find the minimum length of a string t such that s is a concatenation of anagrams of t.

Medium
3144

Minimum Substring Partition of Equal Character Frequency

Partition a string into substrings with equal character frequencies using dynamic programming and state transitions.

Medium
3153

Sum of Digit Differences of All Pairs

Sum of Digit Differences of All Pairs is a problem that involves counting digit differences in pairs from an array of in…

Medium
3184

Count Pairs That Form a Complete Day I

Count all pairs in an array where their sum forms a complete day using hash-based counting for efficiency.

Easy
3185

Count Pairs That Form a Complete Day II

Count the number of valid pairs of hours that form a complete day by checking if their sum is a multiple of 24.

Medium
3186

Maximum Total Damage With Spell Casting

Calculate the maximum total damage by selectively casting spells while avoiding adjacent power conflicts using array sca…

Medium
3223

Minimum Length of String After Operations

Find the minimum length of a string after performing operations based on character frequency.

Medium
3228

Maximum Number of Operations to Move Ones to the End

This problem requires finding the maximum number of operations to move ones to the end of a binary string.

Medium
3238

Find the Number of Winning Players

Find how many players in a game win by picking more balls of a single color than their index position.

Easy
3265

Count Almost Equal Pairs I

Count Almost Equal Pairs I involves finding pairs of elements that can be made equal by swapping at most one digit.

Medium
3267

Count Almost Equal Pairs II

Count the number of almost equal integer pairs in an array using array scanning and hash lookup efficiently.

Hard
3312

Sorted GCD Pair Queries

Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…

Hard
3335

Total Characters in String After Transformations I

Calculate the total number of characters in a string after repeated transformations using dynamic programming and freque…

Medium
3337

Total Characters in String After Transformations II

Calculate the length of a string after repeated transformations using state transition dynamic programming for large t v…

Hard
3371

Identify the Largest Outlier in an Array

Identify the largest outlier in an integer array using scanning and hash lookup for efficient detection and validation.

Medium
3389

Minimum Operations to Make Character Frequencies Equal

This Hard problem asks to transform a string so all character frequencies match using minimal deletions, leveraging dyna…

Hard
3438

Find Valid Pair of Adjacent Digits in String

Identify the first valid adjacent digit pair in a string where each digit appears exactly as many times as its numeric v…

Easy
3442

Maximum Difference Between Even and Odd Frequency I

Find the maximum difference between the frequency of characters in a string with odd and even frequencies.

Easy
3443

Maximum Manhattan Distance After K Changes

Solve Maximum Manhattan Distance After K Changes by scanning prefixes and testing the four diagonal target pairs with li…

Medium
3467

Transform Array by Parity

Transform an array by sorting even numbers first, followed by odd numbers.

Easy
3518

Smallest Palindromic Rearrangement II

Find the k-th lexicographically smallest palindromic rearrangement of a given palindromic string s.

Hard
3527

Find the Most Common Response

Find the most common survey response after eliminating duplicates within each day, using array scanning and hash lookups…

Medium
3541

Find Most Frequent Vowel and Consonant

Given a string, calculate the sum of the most frequent vowel and consonant frequencies.

Easy
3545

Minimum Deletions for At Most K Distinct Characters

You need to delete characters in a string to reduce its distinct characters to at most k.

Easy
3583

Count Special Triplets

Count Special Triplets requires scanning an array while tracking counts of previous and next values efficiently with has…

Medium
3591

Check if Any Element Has Prime Frequency

Check if any element in the array has a prime frequency count, leveraging array scanning and hash table lookup.

Easy

Related Patterns

Counting LeetCode Problems: 149 Solutions