LeetCode
LeetCode 1379: Find a Corresponding Node of a Binary Tree in a Clone of That Tree
·1 min
LeetCode
Easy
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 1379 note: walk both trees in lockstep; when the original reaches target, the clone’s node at the same position is the answer, comparing node identity
LeetCode 473: Matchsticks to Square
·2 mins
LeetCode
Medium
Array
Dynamic-Programming
Backtracking
Bit-Manipulation
LeetCode 473 note: the total must be divisible by 4; place sticks from longest to shortest into one of four sides, skipping a side that would overflow or that equals a side already tried
LeetCode 435: Non-overlapping Intervals
·3 mins
LeetCode
Medium
Array
Dynamic-Programming
Greedy
Sorting
LeetCode 435 note: minimum removals = total minus the maximum kept; sort by right end and greedily keep the one ending earliest
LeetCode 397: Integer Replacement
·2 mins
LeetCode
Medium
Dynamic-Programming
Greedy
Bit-Manipulation
Memoization
LeetCode 397 note: even numbers are always halved; for odd numbers try +1 and -1 with memoized recursion, since n is too large for an n-sized array
LeetCode 396: Rotate Function
·2 mins
LeetCode
Medium
Array
Math
Dynamic-Programming
LeetCode 396 note: F(k) and F(k - 1) differ by one formula: F(k) = F(k - 1) + sum - n × the element moved to the front
LeetCode 337: House Robber III
·2 mins
LeetCode
Medium
Dynamic-Programming
Tree
Depth-First-Search
Binary-Tree
LeetCode 337 note: tree DP where each node returns the best (rob it, skip it) pair; not robbing alternate levels
LeetCode 313: Super Ugly Number
·2 mins
LeetCode
Medium
Array
Math
Dynamic-Programming
LeetCode 313 note: generalizing LC 264 with one pointer per prime; with a heap, avoid pushing the same number many times
LeetCode 338: Counting Bits
·2 mins
LeetCode
Easy
Dynamic-Programming
Bit-Manipulation
LeetCode 338 note: dp[i] = dp[i » 1] + (i & 1), or dp[i] = dp[i - highest power of two] + 1
LeetCode 50: Pow(x, n)
·2 mins
LeetCode
Medium
Math
Recursion
LeetCode 50 note: fast exponentiation, x^n = (x²)^(n/2) with an extra x for odd n; for negative n compute 1 / x^(-n)
LeetCode 264: Ugly Number II
·2 mins
LeetCode
Medium
Hash-Table
Math
Dynamic-Programming
Heap-Priority-Queue
LeetCode 264 note: three pointers mark the next ugly numbers to multiply by 2, 3 and 5; take the minimum each time and advance every pointer that produced it
LeetCode 187: Repeated DNA Sequences
·1 min
LeetCode
Medium
Hash-Table
String
Bit-Manipulation
Sliding-Window
LeetCode 187 note: count every length-10 substring in a hash map and return those seen more than once
LeetCode 142: Linked List Cycle II
·2 mins
LeetCode
Medium
Hash-Table
Linked-List
Two-Pointers
Floyds-Cycle-Finding-Algorithm
LeetCode 142 note: after fast and slow meet, send one back to head and step both one at a time; they meet again at the cycle entry