Counting
Hash Table
·8 mins
Algorithm
Hash-Table
Counting
Array
Counting and frequency of frequencies, using the array itself as a hash table (sign marking), counting several keys at once (rows, columns, diagonals), incremental counts from a fixed left end, and grouping by a normalized key
Merge Sort and Divide-and-Conquer Counting
·7 mins
Algorithm
Merge-Sort
Divide-and-Conquer
Sorting
Counting
Merge sort templates, where to count in inversion-style problems, the linked list version, and common mistakes
LeetCode 493: Reverse Pairs
·4 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Two-Pointers
Counting
LeetCode 493 note: when the counting condition differs from the sort order, scan first, then merge
LeetCode 2426: Number of Pairs Satisfying Inequality
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Two-Pointers
Counting
LeetCode 2426 note: simplify the inequality, then decide whether the matches form a prefix or a suffix
LeetCode LCR 170: Count Inversions (Sword Offer 51)
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Counting
LCR 170 note: count inversions during the merge step
LeetCode 315: Count of Smaller Numbers After Self
·4 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Binary-Indexed-Tree
Counting
LeetCode 315 note: merge sort with indices, plus a BIT solution
LeetCode 2416: Sum of Prefix Scores of Strings
·2 mins
LeetCode
Hard
Trie
String
Counting
LeetCode 2416 note: each Trie node counts the words passing through it, and a word’s answer is the sum of counts along its path
LeetCode 1155: Number of Dice Rolls With Target Sum
·3 mins
LeetCode
Medium
Dynamic-Programming
Counting
LeetCode note for Number of Dice Rolls With Target Sum, rebuilt from the original learning note
LeetCode 3713: Longest Balanced Substring I
·2 mins
LeetCode
Medium
Hash-Table
String
Counting
Enumeration
LeetCode 3713 note: fix the start and extend right; “every character has the same count” means “highest count × kinds = length”, an O(1) check per step
LeetCode 3960: Frequency Balance Subarray
·2 mins
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3960 note: n is only 1000, so fix the left end and extend right while maintaining value -> count and count -> how many; exactly two counts f and 2f means balanced
LeetCode 3913: Sort Vowels by Frequency
·2 mins
LeetCode
Medium
String
Sorting
Counting
LeetCode 3913 note: extract only the vowels, sort by (-count, first occurrence), and put them back into the vowel positions
LeetCode 3843: First Element with Unique Frequency
·1 min
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3843 note: count each value, then count how many values share each count; the first element from the left whose count is its own is the answer