Array
LeetCode 1335: Minimum Difficulty of a Job Schedule
·2 mins
LeetCode
Hard
Dynamic-Programming
Interval-Dp
Array
LeetCode 1335 note: partition DP into d segments; dp(i, k) = the least difficulty starting at job i with k days left, enumerating where today ends while updating today’s maximum
LeetCode 3651: Minimum Cost Path with Teleportations
·2 mins
LeetCode
Hard
Dynamic-Programming
Grid-Dp
Matrix
Array
LeetCode 3651 note: compute layer by layer over teleports; arriving at a cell by teleport costs the previous layer’s minimum over cells with value >= it, found with a running minimum after sorting, followed by the usual right / down grid DP
LeetCode 312: Burst Balloons
·2 mins
LeetCode
Hard
Dynamic-Programming
Interval-Dp
Array
LeetCode 312 note: choose the last balloon k burst in the range (i, j); at that moment its neighbors are i and j, and the two sides are independent subproblems
LeetCode 3660: Jump Game IX
·2 mins
LeetCode
Medium
Dynamic-Programming
Array
LeetCode 3660 note: cutting between i and i+1, if the left max exceeds the right min the two sides reach each other and share the answer; otherwise the left answer is the left max
LeetCode 307: Range Sum Query - Mutable
·3 mins
LeetCode
Medium
Segment-Tree
Binary-Indexed-Tree
Design
Array
LeetCode 307 note: point updates with range sums make prefix sums O(n) per update; a segment tree or Fenwick tree makes both operations O(log n)
LeetCode 3960: Frequency Balance Subarray
·2 mins
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3960 note: n is only 1000, so fix the left end and extend right while maintaining value -> count and count -> how many; exactly two counts f and 2f means balanced
LeetCode 3951: Minimum Energy to Maintain Brightness
·2 mins
LeetCode
Medium
Array
Sorting
LeetCode 3951 note: a bulb lights at most 3 positions, so each time unit needs ceil(brightness / 3) bulbs; merge the intervals for the total time and multiply
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 3917: Count Indices With Opposite Parity
·1 min
LeetCode
Easy
Array
LeetCode 3917 note: scan right to left counting odds and evens seen; each position’s answer is the count of opposite parity to its right
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 3912: Valid Elements in an Array
·2 mins
LeetCode
Easy
Array
LeetCode 3912 note: greater than all on the left means greater than the prefix maximum, and likewise for the right with the suffix maximum; scan both ways and output in original order
LeetCode 3909: Compare Sums of Bitonic Parts
·1 min
LeetCode
Medium
Array
LeetCode 3909 note: walk to the peak and sum each side; the peak belongs to both, so including it or not does not change the comparison