↓Skip to main content

Hard

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 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 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
LeetCode 2858: Minimum Edge Reversals So Every Node Is Reachable
·2 mins
LeetCode Hard Dynamic-Programming Depth-First-Search Breadth-First-Search Graph
LeetCode 2858 note: rerooting DP: count the reversals needed with root 0, then moving the root to a child adds 1 if that edge pointed down and subtracts 1 if it pointed up
LeetCode 968: Binary Tree Cameras
·3 mins
LeetCode Hard Dynamic-Programming Tree Depth-First-Search Binary-Tree Dp-on-Trees
LeetCode 968 note: post-order greedy with three states per node: has a camera, covered, not covered; place a camera only when a child is uncovered, and add one if the root is left uncovered
LeetCode 297: Serialize and Deserialize Binary Tree
·2 mins
LeetCode Hard String Tree Depth-First-Search Breadth-First-Search Design Binary-Tree
LeetCode 297 note: pre-order with null markers identifies the tree uniquely; deserialize by consuming tokens from an iterator
LeetCode 124: Binary Tree Maximum Path Sum
·2 mins
LeetCode Hard Dynamic-Programming Tree Depth-First-Search Binary-Tree Dp-on-Trees
LeetCode 124 note: DFS returns the best downward chain and updates the answer with left chain + node + right chain at every node; drop negative chains
LeetCode 23: Merge k Sorted Lists
·4 mins
LeetCode Hard Linked-List Heap Merge-Sort Divide-and-Conquer
LeetCode 23 note: a heap that holds only k heads, and divide-and-conquer pairwise merging
LeetCode 493: Reverse Pairs
·4 mins
LeetCode Hard Merge-Sort Divide-and-Conquer Two-Pointers Counting
LeetCode 493 note: when the counting condition differs from the sort order, scan first, then merge
LeetCode 4051: Count Subarrays with Distant Sums
·5 mins
LeetCode Hard Merge-Sort Prefix-Sum Binary-Indexed-Tree Biweekly-Contest
LeetCode 4051 note: prefix sums, complement counting, range counting, and the k = 0 edge case
LeetCode 2426: Number of Pairs Satisfying Inequality
·3 mins
LeetCode Hard Merge-Sort Divide-and-Conquer Two-Pointers Counting
LeetCode 2426 note: simplify the inequality, then decide whether the matches form a prefix or a suffix