Array
LeetCode 1052: Grumpy Bookstore Owner
·3 mins
LeetCode
Daily
Medium
Array
Sliding-Window
Fixed-Window
Optimization
LeetCode Problem Solving - Fixed Window with Customer Satisfaction Optimization
LeetCode 1004: Max Consecutive Ones III
·3 mins
LeetCode
Daily
Medium
Array
Sliding-Window
Two-Pointers
Binary-Array
LeetCode Problem Solving - Variable Size Sliding Window with Zero Counting
LeetCode 1343: Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
·3 mins
LeetCode
Daily
Medium
Array
Sliding-Window
Prefix-Sum
Average-Calculation
LeetCode Problem Solving - Fixed Size Sliding Window with Sum Calculation
LeetCode 2874: Maximum Value of an Ordered Triplet II
·2 mins
LeetCode
Medium
Prefix-Sum
Array
LeetCode 2874 note: fix the middle j and take the prefix maximum on the left and the suffix maximum on the right, or scan once tracking the maximum and the best difference
LeetCode 1222: Queens That Can Attack the King
·2 mins
LeetCode
Medium
Array
Matrix
Simulation
LeetCode 1222 note: step outward from the king in eight directions; the first queen met in each direction can attack, with queens in a set for lookups
LeetCode 3627: Maximum Median Sum of Subsequences of Size 3
·2 mins
LeetCode
Medium
Math
Greedy
Sorting
Game-Theory
Array
LeetCode 3627 note: after sorting, each group takes the two largest and the smallest, with the second largest as the median; the answer takes every other value from the end, n / 3 of them
LeetCode 2210: Count Hills and Valleys in an Array
·1 min
LeetCode
Easy
Array
LeetCode 2210 note: treat equal neighbors as one point and remember only the last non-flat direction; up then down is a hill, down then up a valley
Kadane's Algorithm
·2 mins
Algorithm
Kadane
Dynamic-Programming
Array
Maximum subarray DP with an ending-here invariant
LeetCode 665: Non-decreasing Array
·2 mins
LeetCode
Medium
Array
LeetCode 665 note: at a drop, lower nums[i-1] when possible, and only when nums[i] < nums[i-2] raise nums[i] instead; a second drop fails
LeetCode 1248: Count Number of Nice Subarrays
·3 mins
LeetCode
Medium
Sliding-Window
Prefix-Sum
Hash-Table
Array
LeetCode 1248 note: “exactly k odd numbers” is not monotonic, so compute “at most k” minus “at most k - 1”; or use prefix sums with a hash map
LeetCode 1304: Find N Unique Integers Sum up to Zero
·1 min
LeetCode
Easy
Math
Array
LeetCode 1304 note: place 1..n/2 and their negatives so each pair cancels, adding 0 when n is odd
LeetCode 3618: Split Array by Prime Indices
·2 mins
LeetCode
Medium
Math
Number-Theory
Sieve
Array
LeetCode 3618 note: primality is about the index; a sieve of Eratosthenes marks all of 0..n-1 at once, faster than trial division per index