↓Skip to main content

LeetCode

LeetCode 1570: Dot Product of Two Sparse Vectors
·2 mins
LeetCode Medium Two-Pointers Design Hash-Table Array
LeetCode 1570 note: store only non-zero (index, value) pairs, and compute the dot product by merging the two index-sorted lists with two pointers, multiplying only on equal indices
LeetCode 1229: Meeting Scheduler
·2 mins
LeetCode Medium Two-Pointers Sorting Array
LeetCode 1229 note: sort both people’s slots, then find intersections with two pointers as in 986; the first intersection that is long enough is the earliest slot
LeetCode 3835: Count Subarrays With Cost Less Than or Equal to K
·2 mins
LeetCode Medium Sliding-Window Monotonic-Queue Queue Array
LeetCode 3835 note: cost = (max - min) × length only grows as the window grows, so a sliding window counts subarrays; two monotonic deques keep the window’s max and min
LeetCode 3834: Merge Adjacent Equal Elements
·2 mins
LeetCode Medium Stack Simulation Array
LeetCode 3834 note: a stack simulation where a new element merges with an equal top, possibly again with the new top
LeetCode 3833: Count Dominant Indices
·2 mins
LeetCode Easy Array Enumeration
LeetCode 3833 note: keep a suffix sum from the right and compare nums[i] × count > sum on the right, with no floats and without counting itself
LeetCode 3379: Transformed Array
·1 min
LeetCode Easy Array Simulation
LeetCode 3379 note: moving nums[i] steps right or left is nums[(i + nums[i]) % n]; Python’s % returns a non-negative result for negatives too
LeetCode 2054: Two Best Non-Overlapping Events
·2 mins
LeetCode Medium Dynamic-Programming Binary-Search Sorting Heap
LeetCode 2054 note: with at most two events, pair each event with the most valuable event that ends before it starts; sort by end time and use a prefix max with binary search
LeetCode 244: Shortest Word Distance II
·2 mins
LeetCode Medium Two-Pointers Design Hash-Table String Array
LeetCode 244 note: precompute each word’s positions (sorted by construction), then answer each query by merging the two position lists with two pointers, always advancing the smaller one
LeetCode 986: Interval List Intersections
·2 mins
LeetCode Medium Two-Pointers Sweep-Line Array
LeetCode 986 note: two pointers each hold an interval, the intersection is [max(starts), min(ends)], and the interval that ends first cannot meet anything else, so its pointer advances
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)