<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Divide-and-Conquer on</title><link>https://h30306.github.io/blog/tags/divide-and-conquer/</link><description>Recent content in Divide-and-Conquer on</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>hwork0511@gmail.com (Wei Yi Chung)</managingEditor><webMaster>hwork0511@gmail.com (Wei Yi Chung)</webMaster><copyright>© 2026 Wei Yi Chung</copyright><lastBuildDate>Thu, 29 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://h30306.github.io/blog/tags/divide-and-conquer/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 889: Construct Binary Tree from Preorder and Postorder Traversal</title><link>https://h30306.github.io/blog/leetcode/leetcode-889/</link><pubDate>Thu, 29 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-889/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-889/featured.png"/></item><item><title>LeetCode 23: Merge k Sorted Lists</title><link>https://h30306.github.io/blog/leetcode/leetcode-23/</link><pubDate>Tue, 20 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-23/</guid><description>LeetCode 23 note: a heap that holds only k heads, and divide-and-conquer pairwise merging</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-23/featured.png"/></item><item><title>Merge Sort and Divide-and-Conquer Counting</title><link>https://h30306.github.io/blog/algorithm/merge-sort/</link><pubDate>Tue, 20 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/algorithm/merge-sort/</guid><description>Merge sort templates, where to count in inversion-style problems, the linked list version, and common mistakes</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/algorithm/merge-sort/featured.png"/></item><item><title>LeetCode 2426: Number of Pairs Satisfying Inequality</title><link>https://h30306.github.io/blog/leetcode/leetcode-2426/</link><pubDate>Mon, 19 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-2426/</guid><description>LeetCode 2426 note: simplify the inequality, then decide whether the matches form a prefix or a suffix</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-2426/featured.png"/></item><item><title>LeetCode 493: Reverse Pairs</title><link>https://h30306.github.io/blog/leetcode/leetcode-493/</link><pubDate>Mon, 19 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-493/</guid><description>LeetCode 493 note: when the counting condition differs from the sort order, scan first, then merge</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-493/featured.png"/></item><item><title>LeetCode 315: Count of Smaller Numbers After Self</title><link>https://h30306.github.io/blog/leetcode/leetcode-315/</link><pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-315/</guid><description>LeetCode 315 note: merge sort with indices, plus a BIT solution</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-315/featured.png"/></item><item><title>LeetCode 912: Sort an Array</title><link>https://h30306.github.io/blog/leetcode/leetcode-912/</link><pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-912/</guid><description>LeetCode 912 note: hand-written merge sort and the two bugs I hit</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-912/featured.png"/></item><item><title>LeetCode LCR 170: Count Inversions (Sword Offer 51)</title><link>https://h30306.github.io/blog/leetcode/leetcode-lcr-170/</link><pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-lcr-170/</guid><description>LCR 170 note: count inversions during the merge step</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-lcr-170/featured.png"/></item><item><title>LeetCode 327: Count of Range Sum</title><link>https://h30306.github.io/blog/leetcode/leetcode-327/</link><pubDate>Sat, 01 Aug 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-327/</guid><description>LeetCode 327 note: prefix sums plus merge sort counting with two pointers bounding a range, and a log of retyping it over a dozen times</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-327/featured.png"/></item><item><title>LeetCode 1763: Longest Nice Substring</title><link>https://h30306.github.io/blog/leetcode/leetcode-1763/</link><pubDate>Sat, 17 Jan 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-1763/</guid><description>LeetCode 1763 note: a character whose other case never appears cannot be in the answer, so split on it and recurse, preferring the left side on ties</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-1763/featured.png"/></item><item><title>LeetCode 395: Longest Substring with At Least K Repeating Characters</title><link>https://h30306.github.io/blog/leetcode/leetcode-395/</link><pubDate>Sat, 17 Jan 2026 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-395/</guid><description>LeetCode 395 note: &amp;ldquo;every character at least k times&amp;rdquo; is not monotonic, so a direct slide fails; divide and conquer splits on characters with fewer than k occurrences, or fixing the number of distinct characters makes the window slidable</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-395/featured.png"/></item><item><title>LeetCode 109: Convert Sorted List to Binary Search Tree</title><link>https://h30306.github.io/blog/leetcode/leetcode-109/</link><pubDate>Sat, 19 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-109/</guid><description>LeetCode 109 note: take the middle found with fast and slow pointers as the root and recurse on both halves; the height balances naturally</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-109/featured.png"/></item><item><title>LeetCode 148: Sort List</title><link>https://h30306.github.io/blog/leetcode/leetcode-148/</link><pubDate>Thu, 17 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-148/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-148/featured.png"/></item><item><title>LeetCode 324: Wiggle Sort II</title><link>https://h30306.github.io/blog/leetcode/leetcode-324/</link><pubDate>Thu, 17 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-324/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-324/featured.png"/></item><item><title>LeetCode 240: Search a 2D Matrix II</title><link>https://h30306.github.io/blog/leetcode/leetcode-240/</link><pubDate>Sat, 12 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-240/</guid><description>LeetCode 240 note: start at the top-right corner, moving left when larger and down when smaller, eliminating a row or column each step</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-240/featured.png"/></item><item><title>LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal</title><link>https://h30306.github.io/blog/leetcode/leetcode-106/</link><pubDate>Thu, 10 Nov 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-106/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-106/featured.png"/></item><item><title>LeetCode 105: Construct Binary Tree from Preorder and Inorder Traversal</title><link>https://h30306.github.io/blog/leetcode/leetcode-105/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-105/</guid><description>LeetCode 105 note: the first pre-order value is the root, and its position in the in-order tells the left subtree&amp;rsquo;s size; look positions up in a dictionary for O(n)</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-105/featured.png"/></item><item><title>LeetCode 215: Kth Largest Element in an Array</title><link>https://h30306.github.io/blog/leetcode/leetcode-215/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-215/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-215/featured.png"/></item><item><title>LeetCode 973: K Closest Points to Origin</title><link>https://h30306.github.io/blog/leetcode/leetcode-973/</link><pubDate>Sat, 29 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-973/</guid><description>LeetCode 973 note: as in Top-K, keep a size-k max-heap (negated distances) holding the k closest points</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-973/featured.png"/></item><item><title>LeetCode 347: Top K Frequent Elements</title><link>https://h30306.github.io/blog/leetcode/leetcode-347/</link><pubDate>Thu, 27 Oct 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-347/</guid><description>LeetCode 347 note: count first, then take the k most frequent with a size-k heap or a bucket sort indexed by count</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-347/featured.png"/></item><item><title>LeetCode 169: Majority Element</title><link>https://h30306.github.io/blog/leetcode/leetcode-169/</link><pubDate>Sat, 20 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-169/</guid><description>LeetCode 169 note: Boyer-Moore voting, where different values cancel in pairs and the survivor is the one appearing more than half the time</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-169/featured.png"/></item><item><title>LeetCode 108: Convert Sorted Array to Binary Search Tree</title><link>https://h30306.github.io/blog/leetcode/leetcode-108/</link><pubDate>Tue, 16 Aug 2022 00:00:00 +0000</pubDate><author>hwork0511@gmail.com (Wei Yi Chung)</author><guid>https://h30306.github.io/blog/leetcode/leetcode-108/</guid><description>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</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://h30306.github.io/blog/leetcode/leetcode-108/featured.png"/></item></channel></rss>