Greedy
LeetCode 134: Gas Station
·2 mins
LeetCode
Medium
Array
Greedy
LeetCode 134 note: if total gas is short there is no answer; otherwise scan, and whenever the tank goes negative move the start to the next station
LeetCode 11: Container With Most Water
·2 mins
LeetCode
Medium
Array
Two-Pointers
Greedy
LeetCode 11 note: start pointers at both ends and always move the shorter side; moving the taller side only narrows the width without raising the height
LeetCode 1013: Partition Array Into Three Parts With Equal Sum
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 1013 note: the total must be divisible by 3; accumulate from the left, cutting whenever the running sum hits total / 3, and succeed with at least 3 pieces
LeetCode 1005: Maximize Sum Of Array After K Negations
·1 min
LeetCode
Easy
Array
Greedy
Sorting
LeetCode 1005 note: negate the smallest value each time; once the smallest is positive, only the parity of the remaining count matters
LeetCode 942: DI String Match
·1 min
LeetCode
Easy
Array
Two-Pointers
String
Greedy
LeetCode 942 note: two pointers hold the smallest and largest unused values; place the smallest on I and the largest on D
LeetCode 860: Lemonade Change
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 860 note: track only the counts of $5 and $10 bills; for $15 change prefer 10 + 5, since $5 bills are more versatile
LeetCode 680: Valid Palindrome II
·2 mins
LeetCode
Easy
Two-Pointers
String
Greedy
LeetCode 680 note: at the first mismatch the only options are deleting the left or the right character; check whether either remainder is a palindrome
LeetCode 605: Can Place Flowers
·2 mins
LeetCode
Easy
Array
Greedy
LeetCode 605 note: scan left to right and plant in any empty plot whose neighbors are empty; a new flower blocks the next plot, so actually update the array
LeetCode 561: Array Partition
·1 min
LeetCode
Easy
Array
Greedy
Sorting
Counting-Sort
LeetCode 561 note: sort and pair neighbors; each pair’s minimum is the element at an even index, so sum those
LeetCode 455: Assign Cookies
·2 mins
LeetCode
Easy
Array
Two-Pointers
Greedy
Sorting
LeetCode 455 note: sort children and cookies, satisfying the least greedy child with the smallest cookie that suffices; each pointer walks once
LeetCode 409: Longest Palindrome
·2 mins
LeetCode
Easy
Hash-Table
String
Greedy
LeetCode 409 note: use an even number of each character on the two sides, plus one in the middle if any count is odd