Medium
LeetCode 148: Sort List
·2 mins
LeetCode
Medium
Linked-List
Two-Pointers
Divide-and-Conquer
Sorting
LeetCode 148 note: split in half with fast and slow pointers, sort each half recursively and merge; O(n log n) with no extra array
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 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
LeetCode 227: Basic Calculator II
·2 mins
LeetCode
Medium
Math
String
Stack
LeetCode 227 note: read whole numbers, and at each operator apply the previous one: + and - push the number (negated for -), * and / combine with the top