Binary-Search
LeetCode 778: Swim in Rising Water
·3 mins
LeetCode
Hard
Graph
Dijkstra
Binary-Search
LeetCode note for Swim in Rising Water, rebuilt from the original learning note
LeetCode 2838: Maximum Coins Heroes Can Collect
·2 mins
LeetCode
Medium
Binary-Search
Prefix-Sum
Sorting
LeetCode 2838 note: sort monsters by power, build coin prefix sums, and bisect_right per hero
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 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 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 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 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 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
LeetCode 2563: Count the Number of Fair Pairs
·3 mins
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 2563 note: split “sum in [lower, upper]” into “sum <= upper” minus “sum <= lower - 1”, and count each with converging pointers over the sorted array in O(n)
LeetCode 1574: Shortest Subarray to be Removed to Make Array Sorted
·2 mins
LeetCode
Medium
Two-Pointers
Binary-Search
Array
Monotonic-Stack
LeetCode 1574 note: what remains is a non-decreasing prefix plus a non-decreasing suffix; find the longest of each, then join them with two pointers
LeetCode 1498: Number of Subsequences That Satisfy the Given Sum Condition
·2 mins
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 1498 note: only the minimum and maximum matter, so order does not and we can sort; fixing nums[left] as the minimum, the elements between are free, giving 2^(right - left) choices