Greedy
LeetCode 763: Partition Labels
·2 mins
LeetCode
Medium
Hash-Table
Two-Pointers
String
Greedy
LeetCode 763 note: record each letter’s last index, extend the current part’s end while scanning, and cut when the scan reaches it
LeetCode 452: Minimum Number of Arrows to Burst Balloons
·2 mins
LeetCode
Medium
Array
Greedy
Sorting
LeetCode 452 note: sort by end and shoot at the end; only a balloon starting after the arrow needs a new one, and touching ends count as overlapping
LeetCode 4099: Minimum Operations to Sort With Locked Indices
·3 mins
LeetCode
Medium
Array
Merge-Sort
Greedy
LeetCode 4099 note: the swaps needed equal the inversion count; every locked position some element must cross has to be unlocked, so count those, compare with k, and add the inversions counted with merge sort
LeetCode 4098: Minimize the Maximum Value of GCD-Connected Array
·4 mins
LeetCode
Medium
Math
Number-Theory
Greedy
LeetCode 4098 note: value’s smallest prime factor p decides everything: the next element is at least value + p, then even numbers step by 2; the left side is feasible iff value - p >= 2 * index
Stack and Monotonic Stack
·6 mins
Algorithm
Stack
Monotonic-Stack
Greedy
Simulation
Parsing nested structures, simulations that interact with the previous element, monotonic stacks, greedy deletion for the smallest string, and a lazy-deletion Max Stack
Heap and Priority Queue
·6 mins
Algorithm
Heap
Priority-Queue
Greedy
Dijkstra
heapq basics, Top-K, lazy deletion, two heaps, k-way merge, sweep line, and Dijkstra
Greedy
·9 mins
Algorithm
Greedy
Sorting
Intervals
Sort then scan, intervals sorted by right end, left and right passes, pairing and parity invariants, adjacent differences, and “remove what exceeds the average”, each with why greedy is correct
LeetCode 4045: Count Robot Groups
·3 mins
LeetCode
Medium
Stack
Monotonic-Stack
Greedy
LeetCode 4045 note: merge robots already close at t = 0, then go right to left like car fleets, where anything faster than the fleet ahead eventually joins it
LeetCode 2561: Rearranging Fruits
·2 mins
LeetCode
Hard
Greedy
Hash-Table
Sorting
LeetCode 2561 note: every value’s total must be even; sort the excess, and each cheap half item swaps with an expensive one at min(its value, 2 × global minimum)
LeetCode 1354: Construct Target Array With Multiple Sums
·3 mins
LeetCode
Hard
Heap
Math
Greedy
LeetCode 1354 note: work backwards, since the maximum was set last; jump with a modulo when the gap is large
LeetCode 420: Strong Password Checker
·4 mins
LeetCode
Hard
Greedy
String
LeetCode 420 note: three length cases; when too long, delete from runs with len % 3 == 0 first to cancel replacements
LeetCode 2193: Minimum Number of Moves to Make Palindrome
·3 mins
LeetCode
Hard
Two-Pointers
Greedy
String
Binary-Indexed-Tree
LeetCode 2193 note: greedily fix the outer pair: take the last character and swap its leftmost partner to the front, costing that index; the unpaired character ends in the middle, costing its distance there