Array
LeetCode 3423: Maximum Difference Between Adjacent Elements in a Circular Array
·1 min
LeetCode
Easy
Array
LeetCode 3423 note: circular adjacency includes the last and first elements; starting from i = 0 with nums[i - 1] covers it
LeetCode 927: Three Equal Parts
·3 mins
LeetCode
Hard
Math
Array
LeetCode 927 note: every part has the same number of 1s, so count them; the third part always runs to the end of the array, fixing what each part must match, then check the parts do not overlap
LeetCode 2391: Minimum Amount of Time to Collect Garbage
·2 mins
LeetCode
Medium
Prefix-Sum
String
Array
LeetCode 2391 note: pickup time is the total garbage count; each truck only drives to the last house with its type, using a prefix sum of travel
LeetCode 2410: Maximum Matching of Players With Trainers
·2 mins
LeetCode
Medium
Two-Pointers
Greedy
Sorting
Array
LeetCode 2410 note: sort both sides, then same-direction pointers match the weakest player with the smallest trainer that is good enough
LeetCode 3550: Smallest Index With Digit Sum Equal to Index
·1 min
LeetCode
Easy
Math
Array
LeetCode 3550 note: check indices in increasing order, computing each digit sum; the first match is the answer
LeetCode 1979: Find Greatest Common Divisor of Array
·1 min
LeetCode
Easy
Math
Number-Theory
Gcd
Array
LeetCode 1979 note: find the minimum and maximum, then take their GCD with Euclid’s algorithm
LeetCode 2094: Finding 3-Digit Even Numbers
·2 mins
LeetCode
Easy
Hash-Table
Enumeration
Array
LeetCode 2094 note: enumerate the even numbers 100 to 998 instead and check that each digit needed is available; Counter subtraction keeps only positives
LeetCode 1550: Three Consecutive Odds
·1 min
LeetCode
Easy
Array
LeetCode Problem Solving
LeetCode 952: Largest Component Size by Common Factor
·2 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Hash-Table
Array
LeetCode 952 note: sharing a factor ⇔ sharing a prime factor; factor each number and union indices with the same prime factor using Union-Find, with no pairwise GCDs
LeetCode 1920: Build Array from Permutation
·1 min
LeetCode
Easy
Array
Simulation
LeetCode 1920 note: follow the definition ans[i] = nums[nums[i]]; for O(1) extra space, stack the new value times n on top of the old one
LeetCode 2176: Count Equal and Divisible Pairs in an Array
·1 min
LeetCode
Easy
Array
LeetCode 2176 note: n is only 100, so enumerate all pairs; the condition is equal values and the index product i * j divisible by k
LeetCode 164: Maximum Gap
·3 mins
LeetCode
Medium
Bucket-Sort
Radix-Sort
Sorting
Array
LeetCode 164 note: the maximum gap is at least the average gap, so with buckets no wider than that it lies between consecutive non-empty buckets; keep each bucket’s min and max for O(n)