↓Skip to main content

LeetCode

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 32: Longest Valid Parentheses
·3 mins
LeetCode Hard String Dynamic-Programming Stack Bracket-Sequences
LeetCode 32 note: a stack of indices whose bottom is the position just before the current valid run; the length is i - stack[-1]
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 4097: Minimum Value of Merged Integers
·1 min
LeetCode Easy Array String Simulation
LeetCode 4097 note: only merge the fixed pairs (0,1), (2,3), …, stepping by 2, not every adjacent pair
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 25: Reverse Nodes in k-Group
·2 mins
LeetCode Hard Linked-List Recursion
LeetCode 25 note: count the length to know how many full groups to reverse, k nodes each; a dummy head avoids special-casing the first group, and the old group head becomes its 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 834: Sum of Distances in Tree
·3 mins
LeetCode Hard Dynamic-Programming Tree Depth-First-Search Graph Dp-on-Trees
LeetCode 834 note: rerooting DP: compute subtree sizes and ans[0] with root 0, then push ans[child] = ans[parent] - size + (n - size) to every node
LeetCode 460: LFU Cache
·3 mins
LeetCode Hard Hash-Table Linked-List Design Doubly-Linked-List
LeetCode 460 note: key → node, freq → doubly linked list, plus a min_freq; within the same frequency, LRU decides what to evict