Medium
LeetCode 777: Swap Adjacent in LR String
·2 mins
LeetCode
Medium
Two-Pointers
String
LeetCode 777 note: XL→LX moves L left and RX→XR moves R right; after skipping X the order must match, with L only moving left and R only moving right
LeetCode 3829: Design Ride Sharing System
·2 mins
LeetCode
Medium
Queue
Design
Hash-Map
Lazy-Deletion
LeetCode 3829 note: one queue each for riders and drivers; cancellations only update a set, and canceled riders at the front are dropped before matching
LeetCode 3828: Final Element After Subarray Deletions
·2 mins
LeetCode
Medium
Math
Brainteaser
Game-Theory
Array
LeetCode 3828 note: Alice can leave only the first or last element on her first move, guaranteeing max(first, last); Bob can likewise keep only an end, and one deletion changes at most one end, so the answer is max(first, last)
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 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 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 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 3323: Minimize Connected Groups by Inserting Interval
·2 mins
LeetCode
Medium
Sliding-Window
Sorting
Binary-Search
Array
LeetCode 3323 note: merge first; a new interval can join groups l through r ⇔ start of group r − end of group l <= k, so a sliding window finds the most groups one interval can connect
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 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