↓Skip to main content

LeetCode

LeetCode 1888: Minimum Number of Flips to Make the Binary String Alternating
·2 mins
LeetCode Medium Sliding-Window String Dynamic-Programming
LeetCode 1888 note: rotations become length-n windows over s + s; the window’s mismatches against 0101… are diff, and against 1010… they are n - diff
LeetCode 3788: Maximum Score of a Split
·1 min
LeetCode Medium Prefix-Sum Array
LeetCode 3788 note: build the suffix minimum first, then accumulate the prefix sum from the left and try every split
LeetCode 3694: Distinct Points Reachable After Substring Removal
·2 mins
LeetCode Medium Sliding-Window Prefix-Sum Hash-Table String
LeetCode 3694 note: the endpoint is the total displacement minus the removed segment’s displacement; a length-k window tracks that segment and each endpoint goes into a set
LeetCode 2134: Minimum Swaps to Group All 1's Together II
·2 mins
LeetCode Medium Sliding-Window Array
LeetCode 2134 note: the 1s end up in a circular window as long as their count, and the swaps needed equal the 0s in that window; slide around the circle for the minimum
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 2461: Maximum Sum of Distinct Subarrays With Length K
·2 mins
LeetCode Medium Sliding-Window Hash-Table Array
LeetCode 2461 note: in a fixed window of length k, all values are distinct exactly when the number of distinct values equals k
LeetCode 1423: Maximum Points You Can Obtain from Cards
·1 min
LeetCode Medium Sliding-Window Prefix-Sum Array
LeetCode 1423 note: taking k cards from the ends leaves a contiguous middle of n - k cards; find its minimum sum with a fixed-size window
LeetCode 584: Find Customer Referee
·1 min
LeetCode Easy Database Sql
LeetCode 584 note: referee_id != 2 misses NULLs, since comparing with NULL is unknown; add IS NULL explicitly
LeetCode 2841: Maximum Sum of Almost Unique Subarray
·2 mins
LeetCode Medium Sliding-Window Hash-Table Array
LeetCode 2841 note: a fixed window of length k keeps a sum and a count map; the number of distinct values is the map’s size, so delete keys that drop to zero
LeetCode 1757: Recyclable and Low Fat Products
·1 min
LeetCode Easy Database Sql
LeetCode 1757 note: both conditions must hold, so filter with WHERE … AND …
LeetCode 1281: Subtract the Product and Sum of Digits of an Integer
·1 min
LeetCode Easy Math
LeetCode 1281 note: walk the digits once, accumulating product and sum, and return product minus sum
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