Divide-and-Conquer
LeetCode 324: Wiggle Sort II
·2 mins
LeetCode
Medium
Array
Divide-and-Conquer
Greedy
Sorting
LeetCode 324 note: sort, split into a small half and a large half, reverse each, and interleave with small values at even indices and large ones at odd indices
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 240: Search a 2D Matrix II
·2 mins
LeetCode
Medium
Array
Binary-Search
Divide-and-Conquer
Matrix
LeetCode 240 note: start at the top-right corner, moving left when larger and down when smaller, eliminating a row or column each step
LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal
·2 mins
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Tree
LeetCode 106 note: the last post-order value is the root; taking roots from the end of the post-order, build the right subtree before the left
LeetCode 973: K Closest Points to Origin
·1 min
LeetCode
Medium
Array
Math
Divide-and-Conquer
Geometry
LeetCode 973 note: as in Top-K, keep a size-k max-heap (negated distances) holding the k closest points
LeetCode 215: Kth Largest Element in an Array
·2 mins
LeetCode
Medium
Array
Divide-and-Conquer
Sorting
Heap-Priority-Queue
LeetCode 215 note: keep a min-heap of size k whose top is the k-th largest, or use quickselect for O(n) on average
LeetCode 105: Construct Binary Tree from Preorder and Inorder Traversal
·3 mins
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Tree
LeetCode 105 note: the first pre-order value is the root, and its position in the in-order tells the left subtree’s size; look positions up in a dictionary for O(n)
LeetCode 347: Top K Frequent Elements
·1 min
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Sorting
LeetCode 347 note: count first, then take the k most frequent with a size-k heap or a bucket sort indexed by count
LeetCode 169: Majority Element
·2 mins
LeetCode
Easy
Array
Hash-Table
Divide-and-Conquer
Sorting
LeetCode 169 note: Boyer-Moore voting, where different values cancel in pairs and the survivor is the one appearing more than half the time
LeetCode 108: Convert Sorted Array to Binary Search Tree
·2 mins
LeetCode
Easy
Array
Divide-and-Conquer
Tree
Binary-Search-Tree
LeetCode 108 note: the middle element becomes the root and each half recurses; the halves differ by at most one, so the tree is balanced