↓Skip to main content

Greedy

LeetCode 376: Wiggle Subsequence
·3 mins
LeetCode Medium Dynamic-Programming Greedy
LeetCode note for Wiggle Subsequence, rebuilt from the original learning note
LeetCode 122: Best Time To Buy And Sell Stock II
·2 mins
LeetCode Medium Dynamic-Programming Greedy State-Machine
LeetCode note for Best Time To Buy And Sell Stock II, rebuilt from the original learning note
LeetCode 3919: Minimum Cost to Move Between Indices
·2 mins
LeetCode Medium Greedy Prefix-Sum Array
LeetCode 3919 note: walk one step at a time, each costing 1 (when the next index is the closest) or the gap; jumping is never cheaper, so answer queries with prefix sums
LeetCode 55: Jump Game
·2 mins
LeetCode Medium Greedy
LeetCode note for Jump Game, rebuilt from the original learning note
LeetCode 45: Jump Game II
·3 mins
LeetCode Medium Greedy Bfs
LeetCode note for Jump Game II, rebuilt from the original learning note
LeetCode 3914: Minimum Operations to Make Array Non Decreasing
·2 mins
LeetCode Medium Greedy Array
LeetCode 3914 note: adding x to a range raises only the difference at its left edge by x, so the answer is the sum of all drops
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 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
LeetCode 3684: Maximize Sum of At Most K Distinct Elements
·1 min
LeetCode Easy Greedy Sorting Hash-Table
LeetCode 3684 note: all values are positive, so deduplicate and take the k largest in descending order
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