LeetCode
LeetCode 812: Largest Triangle Area
·2 mins
LeetCode
Easy
Array
Math
Geometry
Polygons
LeetCode 812 note: with at most 50 points, enumerate every triple and take the largest shoelace area
LeetCode 806: Number of Lines To Write String
·2 mins
LeetCode
Easy
Array
String
LeetCode 806 note: simulate writing, wrapping when the next letter would exceed 100; landing exactly on 100 stays on the line
LeetCode 804: Unique Morse Code Words
·1 min
LeetCode
Easy
Array
Hash-Table
String
LeetCode 804 note: translate each word into a Morse string and count the distinct results with a set
LeetCode 796: Rotate String
·2 mins
LeetCode
Easy
String
String-Matching
LeetCode 796 note: goal is a rotation of s exactly when the lengths match and goal occurs in s + s
LeetCode 783: Minimum Distance Between BST Nodes
·2 mins
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Search-Tree
LeetCode 783 note: a BST’s in-order is ascending, so the minimum difference is between in-order neighbors; remember the previous value and compare
LeetCode 771: Jewels and Stones
·1 min
LeetCode
Easy
Hash-Table
String
LeetCode 771 note: put jewels in a set and count how many stones are in it
LeetCode 766: Toeplitz Matrix
·2 mins
LeetCode
Easy
Array
Matrix
LeetCode 766 note: every diagonal is constant exactly when each cell equals its upper-left neighbor
LeetCode 762: Prime Number of Set Bits in Binary Representation
·1 min
LeetCode
Easy
Math
Bit-Manipulation
Primality-Test
LeetCode 762 note: numbers are below 10^6 < 2^20, so the set-bit count is at most 19; check it against a small set of primes
LeetCode 748: Shortest Completing Word
·2 mins
LeetCode
Easy
Array
Hash-Table
String
LeetCode 748 note: count the plate’s letters in lowercase, then find the shortest word covering every count, taking the earliest on ties
LeetCode 747: Largest Number At Least Twice of Others
·2 mins
LeetCode
Easy
Array
Sorting
LeetCode 747 note: find the largest and second largest in one pass and return the largest’s index if it is at least twice the second; multiply to avoid dividing by zero
LeetCode 744: Find Smallest Letter Greater Than Target
·1 min
LeetCode
Easy
Array
Binary-Search
LeetCode 744 note: find the first letter > target (an upper bound), wrapping around to the first letter if none exists
LeetCode 733: Flood Fill
·2 mins
LeetCode
Easy
Array
Depth-First-Search
Breadth-First-Search
Matrix
LeetCode 733 note: DFS or BFS from the start, recoloring 4-directional cells that share the start’s original color; return immediately if the colors are equal