↓Skip to main content

LeetCode

LeetCode 3827: Count Monobit Integers
·1 min
LeetCode Easy Bit-Manipulation Enumeration
LeetCode 3827 note: the only numbers with all-equal bits are 0 and 2^k - 1, so the count is (n + 1).bit_length()
LeetCode 2337: Move Pieces to Obtain a String
·2 mins
LeetCode Medium Two-Pointers String
LeetCode 2337 note: after skipping blanks the piece order must match; L only moves left and R only moves right, so each L’s start index must be >= its target index and each R’s must be <=
LeetCode 1537: Get the Maximum Score
·3 mins
LeetCode Hard Dynamic-Programming Two-Pointers Greedy Array
LeetCode 1537 note: two sorted arrays can switch only at shared values; merge with two pointers, keep a running sum per path, and at a shared value set both to the larger sum plus that value
LeetCode 809: Expressive Words
·3 mins
LeetCode Medium Two-Pointers String Array
LeetCode 809 note: two pointers compare runs of equal characters; when the lengths differ, the run in s must be at least 3 and no shorter than the word’s run, and both strings must end together
LeetCode 442: Find All Duplicates in an Array
·1 min
LeetCode Medium Hash-Table Array
LeetCode 442 note: values are in 1..n, so mark v with the sign of nums[v-1]; on the second visit it is already negative
LeetCode 41: First Missing Positive
·3 mins
LeetCode Hard Hash-Table Array
LeetCode 41 note: the answer is in 1..n+1; replace impossible values with n+1 (not 0) and mark v as seen with the sign of nums[v-1]
LeetCode 3824: Minimum K to Reduce Array Within Limit
·2 mins
LeetCode Medium Binary-Search Math
LeetCode 3824 note: binary search on k with a monotonic check; the upper bound must reach n because there are at least n operations
LeetCode 3823: Reverse Letters Then Special Characters in a String
·2 mins
LeetCode Easy Two-Pointers String
LeetCode 3823 note: two converging-pointer passes, swapping only letters the first time and only special characters the second
LeetCode 2570: Merge Two 2D Arrays by Summing Values
·2 mins
LeetCode Easy Two-Pointers Array
LeetCode 2570 note: merge two id-sorted arrays with two pointers, adding values when ids match
LeetCode 2540: Minimum Common Value
·2 mins
LeetCode Easy Two-Pointers Array
LeetCode 2540 note: one pointer per sorted array, advance the smaller side, and the first match is the answer
LeetCode 976: Largest Perimeter Triangle
·2 mins
LeetCode Easy Math Greedy Sorting Geometry Array
LeetCode 976 note: after sorting, check consecutive triples from the largest down; the first with a + b > c gives the largest perimeter
LeetCode 581: Shortest Unsorted Continuous Subarray
·2 mins
LeetCode Medium Two-Pointers Greedy Sorting Array Monotonic-Stack
LeetCode 581 note: scanning left to right with a running max, the last index below it is the right boundary; scanning right to left with a running min, the last index above it is the left boundary