↓Skip to main content

Medium

LeetCode 763: Partition Labels
·2 mins
LeetCode Medium Hash-Table Two-Pointers String Greedy
LeetCode 763 note: record each letter’s last index, extend the current part’s end while scanning, and cut when the scan reaches it
LeetCode 452: Minimum Number of Arrows to Burst Balloons
·2 mins
LeetCode Medium Array Greedy Sorting
LeetCode 452 note: sort by end and shoot at the end; only a balloon starting after the arrow needs a new one, and touching ends count as overlapping
LeetCode 1011: Capacity To Ship Packages Within D Days
·2 mins
LeetCode Medium Array Binary-Search
LeetCode 1011 note: binary search on the answer over [max(weights), sum(weights)], checking the day count by filling greedily in order
LeetCode 4099: Minimum Operations to Sort With Locked Indices
·3 mins
LeetCode Medium Array Merge-Sort Greedy
LeetCode 4099 note: the swaps needed equal the inversion count; every locked position some element must cross has to be unlocked, so count those, compare with k, and add the inversions counted with merge sort
LeetCode 4098: Minimize the Maximum Value of GCD-Connected Array
·4 mins
LeetCode Medium Math Number-Theory Greedy
LeetCode 4098 note: value’s smallest prime factor p decides everything: the next element is at least value + p, then even numbers step by 2; the left side is feasible iff value - p >= 2 * index
LeetCode 328: Odd Even Linked List
·2 mins
LeetCode Medium Linked-List
LeetCode 328 note: build one list from odd positions and one from even positions, then append the even list to the odd one; remember to cut the even list’s tail
LeetCode 2385: Amount of Time for Binary Tree to Be Infected
·2 mins
LeetCode Medium Hash-Table Tree Depth-First-Search Breadth-First-Search Binary-Tree
LeetCode 2385 note: turn the tree into an undirected graph and BFS from start; the number of levels minus one is the answer
LeetCode 146: LRU Cache
·3 mins
LeetCode Medium Hash-Table Linked-List Design Doubly-Linked-List
LeetCode 146 note: a hash map finds nodes and a doubly linked list keeps the usage order; both get and updating an existing key must move the node to the front
LeetCode 889: Construct Binary Tree from Preorder and Postorder Traversal
·2 mins
LeetCode Medium Array Hash-Table Divide-and-Conquer Tree Binary-Tree
LeetCode 889 note: keep the current path on a stack; when its top equals the next postorder value that subtree is complete and is popped; new nodes go left first
LeetCode 863: All Nodes Distance K in Binary Tree
·2 mins
LeetCode Medium Hash-Table Tree Depth-First-Search Breadth-First-Search Binary-Tree
LeetCode 863 note: turn the tree into an undirected graph (adding edges to parents), then BFS k steps from target
LeetCode 437: Path Sum III
·2 mins
LeetCode Medium Tree Depth-First-Search Binary-Tree
LeetCode 437 note: prefix sums on a tree with a hash map: look up prefix - target before adding the current prefix, and undo it when leaving the node
LeetCode 652: Find Duplicate Subtrees
·2 mins
LeetCode Medium Hash-Table Tree Depth-First-Search Binary-Tree
LeetCode 652 note: encode every subtree in post-order and report it on its second occurrence; string keys are O(n^2) worst case, (val, left id, right id) ids make it O(n)