counting
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
Pattern Bridge
High-Pressure Round
Majority Element
Find the majority element in an array, where the element appears more than n/2 times, using efficient algorithms.
Majority Element II
Identify all elements in an integer array appearing more than ⌊ n/3 ⌋ times using efficient array scanning and hash coun…
Bulls and Cows
Solve the Bulls and Cows problem using hash tables and string manipulation to track exact and misplaced digits.
Top K Frequent Elements
Find the k most frequent elements from an array using efficient algorithms like hashing and sorting.
Ransom Note
Determine if a ransom note can be constructed from a magazine's letters using hash tables and string counting techniques…
First Unique Character in a String
Find the index of the first non-repeating character in a string using efficient queue-driven state processing.
Sort Characters By Frequency
Sort Characters By Frequency requires counting characters efficiently and rearranging a string in descending frequency o…
Longest Harmonious Subsequence
Find the length of the longest harmonious subsequence in an integer array using array scanning and hash-based frequency …
Task Scheduler
Task Scheduler is solved by counting task frequencies and computing how cooldown gaps force idle slots around the most f…
Top K Frequent Words
Solve Top K Frequent Words by counting each word, then ordering ties alphabetically so frequency wins before lexicograph…
Reorganize String
Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.
Subdomain Visit Count
The Subdomain Visit Count problem requires counting the visits to all subdomains of a given domain from a list of count-…
Most Common Word
Find the most frequent non-banned word in a paragraph, excluding punctuation, using an efficient array scan and hash tab…
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.
Uncommon Words from Two Sentences
Find uncommon words from two sentences by counting word frequencies using hash tables.
RLE Iterator
Design an efficient iterator for a run-length encoded array, handling large counts and sequential access correctly every…
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.
3Sum With Multiplicity
Count all unique triplets in an integer array whose sum equals the target, handling multiplicity efficiently using hashi…
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.
Subarrays with K Different Integers
Find subarrays with exactly k distinct integers in an integer array using sliding window and hash lookup techniques.
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.
Distant Barcodes
Rearrange barcodes in an array so that no two adjacent elements are equal, using a greedy approach and hash table for ef…
Letter Tile Possibilities
Compute all unique non-empty sequences from given letter tiles using backtracking search with pruning efficiently.
Largest Values From Labels
Maximize the sum of selected item values while respecting label use limits using array scanning and hash tracking.
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.
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…
Maximum Number of Balloons
Find the maximum number of times the word 'balloon' can be formed from characters of the given string.
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'.
Count Servers that Communicate
Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…
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.
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.
Rank Teams by Votes
Rank Teams by Votes requires counting position-based votes and resolving ties with array scanning and hash lookup techni…
Increasing Decreasing String
Reorder the string based on a specific algorithm using hash tables and string manipulation.
Find Lucky Integer in an Array
Identify the largest lucky integer in an array by counting frequencies and comparing values with their occurrences effic…
Construct K Palindrome Strings
Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…
Minimum Number of Frogs Croaking
Determine the minimum number of frogs required to sequentially produce all croaks in a mixed frog croak string efficient…
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…
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 …
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…
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.
Design Parking System
Implement a class to manage a parking lot with fixed slots for big, medium, and small cars, tracking occupancy efficient…
Determine if Two Strings Are Close
Check if two strings can transform into each other using letter swaps and frequency reorganizations, leveraging hash tab…
Count the Number of Consistent Strings
Count the number of strings fully composed of allowed characters using array scanning and hash lookup for efficiency.
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.
Tuple with Same Product
Given an array of distinct integers, return the number of tuples where the product of two pairs is the same.
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.
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.
Sum of Unique Elements
Given an array, find the sum of all its unique elements by identifying those that appear only once.
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…
Sum of Beauty of All Substrings
Calculate the total beauty of all substrings by counting character frequencies and computing frequency differences effic…
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.
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.
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…
Number of Different Subsequences GCDs
Given an array of positive integers, find the number of different subsequences' GCDs.
Maximum Population Year
Find the earliest year with the highest population using an array plus counting approach.
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…
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…
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…
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.
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.
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.
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.
Detect Squares
Detect Squares requires tracking points on a 2D plane to quickly count all possible axis-aligned squares using efficient…
Longest Subsequence Repeated k Times
Find the longest subsequence repeated k times in a string using backtracking search with pruning.
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…
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…
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…
Next Greater Numerically Balanced Number
Find the smallest numerically balanced number greater than a given integer using backtracking search and pruning.
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…
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…
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…
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…
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.
Find All Lonely Numbers in the Array
Find lonely numbers in an array where each lonely number appears once and has no adjacent values.
Minimum Operations to Make the Array Alternating
Given an array, calculate the minimum number of operations needed to make it alternating.
Construct String With Repeat Limit
Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …
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…
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.
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…
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…
Minimum Rounds to Complete All Tasks
The problem requires finding the minimum rounds to complete tasks, focusing on greedy algorithms and hash table lookups.
Intersection of Multiple Arrays
Find integers that are common across all arrays in a given list of arrays.
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…
Check if Number Has Equal Digit Count and Digit Value
Determine if a number's digits correspond to their counts in the string representation.
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…
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.
Maximum Number of Pairs in Array
Given an array, count how many pairs can be formed and how many leftovers remain after pairing.
Best Poker Hand
Determine the strongest poker hand from five cards using array scanning and hash table counting techniques efficiently.
First Letter to Appear Twice
Find the first letter that repeats in a string using hash table tracking and early detection for efficiency.
Count Number of Bad Pairs
Count the number of bad pairs in an array where the difference between indices and values does not match.
Largest Palindromic Number
Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.
Most Frequent Even Element
Identify the most frequent even element in an array using counting and hash lookup, handling ties by choosing the smalle…
Sum of Prefix Scores of Strings
The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …
Remove Letter To Equalize Frequency
Determine if removing a single letter from a string can make all remaining letters have identical frequency efficiently.
Count Number of Distinct Integers After Reverse Operations
This problem requires counting distinct integers after performing reverse operations on each integer in an array.
Destroy Sequential Targets
Find the minimum seed value to destroy the most targets on a number line, using array scanning and hash lookup.
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.
Count Pairs Of Similar Strings
Count similar string pairs by converting each word into a character-set signature and counting matching signatures effic…
Count Anagrams
Learn to count distinct anagrams for a multi-word string using hash tables, math, and combinatorics efficiently.
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…
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…
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…
Minimum Cost to Split an Array
Minimize the cost of splitting an array into k subarrays by calculating importance values and applying dynamic programmi…
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.
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.
Furthest Point From Origin
Determine the maximum distance from origin using string moves and counting underscores optimally for efficient calculati…
Minimum Array Length After Pair Removals
This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.
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.
Count Tested Devices After Test Operations
Simulate testing devices based on battery percentages to determine how many pass the test operations in sequence.
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…
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…
Count Elements With Maximum Frequency
Count Elements With Maximum Frequency is solved by counting each value, tracking the highest count, and summing matching…
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.
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…
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.
Most Frequent Prime
Find the most frequent prime over 10 from numbers generated by scanning a 2D matrix in all straight directions efficient…
Split the Array
Determine if an even-length array can be split into two parts with all distinct elements using hash lookup scanning.
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.
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…
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.
Minimum Deletions to Make String K-Special
Minimize deletions to make a string k-special by adjusting character frequencies.
Right Triangles
Count all possible right triangles in a 2D boolean grid using array scanning and hash lookup for efficiency.
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…
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.
Minimum Substring Partition of Equal Character Frequency
Partition a string into substrings with equal character frequencies using dynamic programming and state transitions.
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…
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.
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.
Maximum Total Damage With Spell Casting
Calculate the maximum total damage by selectively casting spells while avoiding adjacent power conflicts using array sca…
Minimum Length of String After Operations
Find the minimum length of a string after performing operations based on character frequency.
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.
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.
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.
Count Almost Equal Pairs II
Count the number of almost equal integer pairs in an array using array scanning and hash lookup efficiently.
Sorted GCD Pair Queries
Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…
Total Characters in String After Transformations I
Calculate the total number of characters in a string after repeated transformations using dynamic programming and freque…
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…
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.
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…
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…
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.
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…
Transform Array by Parity
Transform an array by sorting even numbers first, followed by odd numbers.
Smallest Palindromic Rearrangement II
Find the k-th lexicographically smallest palindromic rearrangement of a given palindromic string s.
Find the Most Common Response
Find the most common survey response after eliminating duplicates within each day, using array scanning and hash lookups…
Find Most Frequent Vowel and Consonant
Given a string, calculate the sum of the most frequent vowel and consonant frequencies.
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.
Count Special Triplets
Count Special Triplets requires scanning an array while tracking counts of previous and next values efficiently with has…
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.