Counting
LeetCode 3839: Number of Prefix Connected Groups
·1 min
LeetCode
Medium
Hash-Table
String
Counting
LeetCode 3839 note: words sharing the first k characters are connected, so count by word[:k]; exclude words shorter than k
LeetCode 923: 3Sum With Multiplicity
·4 mins
LeetCode
Medium
Two-Pointers
Sorting
Hash-Table
Counting
Array
LeetCode 923 note: sort, fix the first number, and find the other two with converging pointers; equal end values are counted with a combination, different ones by multiplying each end’s duplicate count
LeetCode 1782: Count Pairs Of Nodes
·3 mins
LeetCode
Hard
Two-Pointers
Graph
Sorting
Hash-Table
Counting
LeetCode 1782 note: count pairs with deg[a] + deg[b] > q using sorted degrees and converging pointers, then correct the over-count for pairs that share edges
LeetCode 992: Subarrays with K Different Integers
·2 mins
LeetCode
Hard
Sliding-Window
Hash-Table
Counting
Array
LeetCode 992 note: “exactly k kinds” = “at most k” − “at most k - 1”, where each at-most window adds right - left + 1 per right end
LeetCode 3805: Count Caesar Cipher Pairs
·2 mins
LeetCode
Medium
Math
Hash-Table
String
Counting
LeetCode 3805 note: shift each string so its first letter is a, making Caesar-equivalent strings identical, then count pairs per normalized form
LeetCode 3679: Minimum Discards to Balance Inventory
·3 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Simulation
Counting
Array
LeetCode 3679 note: the rule already decides what must be discarded, so simulate it; the length-w window counts only kept arrivals, and discarded ones must not be subtracted when they leave
LeetCode 1512: Number of Good Pairs
·1 min
LeetCode
Easy
Math
Hash-Table
Counting
Array
LeetCode 1512 note: count while scanning; each number pairs with every earlier equal number, so add its current count to the answer
LeetCode 3712: Sum of Elements With Frequency Divisible by K
·1 min
LeetCode
Easy
Hash-Table
Counting
Array
LeetCode 3712 note: count each value, and for counts divisible by k add value × count
LeetCode 2131: Longest Palindrome by Concatenating Two Letter Words
·2 mins
LeetCode
Medium
Greedy
Hash-Table
String
Counting
LeetCode 2131 note: pair each word with its reverse on both sides; self-palindromes also pair with each other, and only one leftover can sit in the middle
LeetCode 1497: Check If Array Pairs Are Divisible by k (Remainder Pairing, Modulo)
·2 mins
LeetCode
Daily
Medium
Array
Hash-Map
Complement
Counting
Math
Modulo
Remainder pairing with a hash map; handle 0 and k/2 remainders carefully.
LeetCode 3639: Minimum Time to Activate String
·3 mins
LeetCode
Medium
Binary-Search
Counting
String
LeetCode 3639 note: each new star adds (left distance) × (right distance) new substrings; or binary search on time
LeetCode 3545: Minimum Deletions for At Most K Distinct Characters
·1 min
LeetCode
Easy
Greedy
Hash-Table
String
Sorting
Counting
LeetCode 3545 note: reducing the number of kinds means deleting whole kinds, starting from the least frequent