Easy
LeetCode 1018: Binary Prefix Divisible By 5
·1 min
LeetCode
Easy
Array
Bit-Manipulation
LeetCode 1018 note: each new bit turns the prefix into x = 2x + bit, so keep only x mod 5 and the number never grows
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 1002: Find Common Characters
·1 min
LeetCode
Easy
Array
Hash-Table
String
LeetCode 1002 note: count each word and intersect all Counters (minimum count per character), then expand
LeetCode 993: Cousins in Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 993 note: cousins share a depth but not a parent; record x’s and y’s depth and parent during DFS and compare
LeetCode 989: Add to Array-Form of Integer
·2 mins
LeetCode
Easy
Array
Math
LeetCode 989 note: treat k as the carry, add from the last element backwards, and keep prepending digits while k remains
LeetCode 977: Squares of a Sorted Array
·1 min
LeetCode
Easy
Array
Two-Pointers
Sorting
LeetCode 977 note: the largest squares are at the two ends, so compare the ends with two pointers and fill the result from the back
LeetCode 965: Univalued Binary Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 965 note: every value must equal the root’s; compare values while recursing, not the booleans the recursion returns
LeetCode 961: N-Repeated Element in Size 2N Array
·1 min
LeetCode
Easy
Array
Hash-Table
Pigeonhole-Principle
LeetCode 961 note: the other n values are distinct, so the first value seen twice is the answer
LeetCode 953: Verifying an Alien Dictionary
·2 mins
LeetCode
Easy
Array
Hash-Table
String
LeetCode 953 note: map letters to their alien index and compare each adjacent pair at the first differing character; with no difference, the shorter must come first
LeetCode 944: Delete Columns to Make Sorted
·1 min
LeetCode
Easy
Array
String
Longest-Increasing-Subsequence
LeetCode 944 note: take each column with zip(*strs) and count the columns that are not non-decreasing
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