Two-Pointers
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 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 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
LeetCode 3555: Smallest Subarray to Sort in Every Sliding Window
·2 mins
LeetCode
Medium
Two-Pointers
Greedy
Sorting
Array
Monotonic-Stack
LeetCode 3555 note: every length-k window is one instance of LeetCode 581; with n only 1000, two O(k) scans per window are enough
LeetCode 1793: Maximum Score of a Good Subarray
·3 mins
LeetCode
Hard
Two-Pointers
Greedy
Binary-Search
Array
Monotonic-Stack
LeetCode 1793 note: expand from k toward the larger neighbor each step so the minimum stays as large as possible for each length; at a boundary, only the other side can grow
LeetCode 1989: Maximum Number of People That Can Be Caught in Tag
·3 mins
LeetCode
Medium
Two-Pointers
Greedy
Array
LeetCode 1989 note: process the “it” players left to right, each catching the leftmost uncaught person in range, with a right-only pointer to the next candidate
LeetCode 2972: Count the Number of Incremovable Subarrays II
·2 mins
LeetCode
Hard
Two-Pointers
Binary-Search
Array
LeetCode 2972 note: what remains is a strictly increasing prefix plus suffix; for each valid prefix end, a right-only pointer finds the first suffix start that can follow it, and every later start works too
LeetCode 2122: Recover the Original Array
·3 mins
LeetCode
Hard
Two-Pointers
Sorting
Hash-Table
Enumeration
Array
LeetCode 2122 note: the smallest number is always in lower, so enumerating its partner fixes k; after sorting, two pointers pair each smallest unmatched number with the number 2k above it
LeetCode 658: Find K Closest Elements
·3 mins
LeetCode
Medium
Two-Pointers
Binary-Search
Sliding-Window
LeetCode 658 note: shrink two pointers from both ends to length k, or binary search the window start
LeetCode 633: Sum of Square Numbers
·2 mins
LeetCode
Medium
Two-Pointers
Math
Binary-Search
LeetCode 633 note: converge a from 0 and b from isqrt(c); shrink b when the sum is too big and grow a when it is too small; watch for 0, a == b, and floating-point square roots