<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>LeetCode on Jeanphilo Blog</title><link>https://shio-chan-dev.github.io/jeanblog/categories/leetcode/</link><description>Recent content in LeetCode on Jeanphilo Blog</description><generator>Hugo -- 0.159.2</generator><language>en-us</language><lastBuildDate>Fri, 03 Apr 2026 17:54:22 +0800</lastBuildDate><atom:link href="https://shio-chan-dev.github.io/jeanblog/categories/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>Hot100: Permutations (used[] Backtracking ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/backtracking/46-permutations/</link><pubDate>Fri, 03 Apr 2026 17:54:22 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/backtracking/46-permutations/</guid><description>A practical guide to LeetCode 46 covering used[] state tracking, leaf-only collection, and runnable multi-language implementations.</description></item><item><title>Hot100: Subsets (Backtracking / startIndex ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/backtracking/78-subsets/</link><pubDate>Thu, 02 Apr 2026 13:48:57 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/backtracking/78-subsets/</guid><description>A practical guide to LeetCode 78 covering subset backtracking, the startIndex invariant, and runnable multi-language implementations.</description></item><item><title>LeetCode 133: Clone Graph Hash Map + DFS/BFS ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/133-clone-graph/</link><pubDate>Thu, 19 Mar 2026 13:18:26 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/133-clone-graph/</guid><description>Clone a connected undirected graph by mapping original nodes to cloned nodes, with DFS and BFS variants, cycle handling, correctness reasoning, and runnable implementations in six languages.</description></item><item><title>LeetCode 2089: Find Target Indices After Sorting Array ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/2089-find-target-indices-after-sorting-array/</link><pubDate>Wed, 18 Mar 2026 13:49:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/2089-find-target-indices-after-sorting-array/</guid><description>Sort the array, locate the target block with lower and upper bounds, and return every target index, with tradeoff analysis, engineering mappings, and runnable implementations in six languages.</description></item><item><title>LeetCode 2529: Maximum Count of Positive Integer and Negative Integer ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/2529-maximum-count-of-positive-integer-and-negative-integer/</link><pubDate>Wed, 18 Mar 2026 13:49:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/2529-maximum-count-of-positive-integer-and-negative-integer/</guid><description>Count negatives and positives in a sorted array by locating the boundaries around zero with lower-bound and upper-bound binary search, with engineering mappings and runnable implementations in six languages.</description></item><item><title>LeetCode 34: Find First and Last Position of Element in Sorted Array ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/34-find-first-and-last-position-of-element-in-sorted-array/</link><pubDate>Wed, 18 Mar 2026 13:49:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/34-find-first-and-last-position-of-element-in-sorted-array/</guid><description>Find the start and end positions of a target in a sorted array by combining lower-bound and upper-bound binary search, with boundary reasoning, engineering mappings, and runnable implementations in six languages.</description></item><item><title>LeetCode 35: Search Insert Position Lower-Bound Binary Search ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/35-search-insert-position/</link><pubDate>Wed, 18 Mar 2026 13:49:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/35-search-insert-position/</guid><description>Find the insertion index of a target in a sorted array with lower-bound binary search in O(log n), with boundary reasoning, engineering mappings, and runnable implementations in six languages.</description></item><item><title>LeetCode 744: Find Smallest Letter Greater Than Target Upper-Bound ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/744-find-smallest-letter-greater-than-target/</link><pubDate>Wed, 18 Mar 2026 13:49:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/binary-search/744-find-smallest-letter-greater-than-target/</guid><description>Find the smallest character strictly greater than a target in a sorted circular array by using upper-bound binary search and wrap-around logic, with pitfalls, engineering mappings, and runnable implementations in six languages.</description></item><item><title>Hot100: Binary Tree Level Order Traversal (BFS / DFS ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/102-binary-tree-level-order-traversal/</link><pubDate>Mon, 16 Mar 2026 13:00:56 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/102-binary-tree-level-order-traversal/</guid><description>A practical guide to LeetCode 102 covering level-by-level BFS, level-size boundaries, DFS depth buckets, and runnable multi-language implementations.</description></item><item><title>Hot100: Symmetric Tree (Mirror Recursion / BFS ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/101-symmetric-tree/</link><pubDate>Mon, 16 Mar 2026 13:00:55 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/101-symmetric-tree/</guid><description>A practical guide to LeetCode 101 covering mirror recursion, pairwise BFS checks, symmetry contracts, and runnable multi-language implementations.</description></item><item><title>Hot100: Same Tree (Synchronous Recursion / BFS ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/100-same-tree/</link><pubDate>Mon, 16 Mar 2026 13:00:54 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/100-same-tree/</guid><description>A practical guide to LeetCode 100 covering synchronous recursion, pairwise BFS validation, structural equivalence, and runnable multi-language implementations.</description></item><item><title>Hot100: Invert Binary Tree (Recursion / BFS ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/226-invert-binary-tree/</link><pubDate>Fri, 06 Mar 2026 17:58:23 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/226-invert-binary-tree/</guid><description>A practical guide to LeetCode 226 covering tree mirroring, recursive left-right swaps, BFS traversal, and engineering mappings.</description></item><item><title>Hot100: Maximum Depth of Binary Tree (DFS / BFS ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/104-maximum-depth-of-binary-tree/</link><pubDate>Fri, 06 Mar 2026 17:58:22 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/104-maximum-depth-of-binary-tree/</guid><description>A practical guide to LeetCode 104 covering the depth definition, recursive DFS, level-order BFS, engineering mappings, and runnable multi-language implementations.</description></item><item><title>Hot100: Binary Tree Inorder Traversal (Recursion / Stack ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/94-binary-tree-inorder-traversal/</link><pubDate>Fri, 06 Mar 2026 17:58:21 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/binary-tree/94-binary-tree-inorder-traversal/</guid><description>A practical guide to LeetCode 94 covering left-root-right traversal, recursion, explicit stacks, engineering mappings, and runnable multi-language implementations.</description></item><item><title>LeetCode 146: LRU Cache Design with O(1) Hash Map + Doubly Linked List</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/146-lru-cache/</link><pubDate>Thu, 12 Feb 2026 13:51:08 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/146-lru-cache/</guid><description>Implement LRUCache with O(1) average get/put by combining a hash map for lookup and a doubly linked list for recency order. Includes ACERS reasoning, engineering mapping, and runnable multi-language code.</description></item><item><title>LeetCode 19: Remove Nth Node From End of List (One-pass Two Pointers) ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/19-remove-nth-node-from-end-of-list/</link><pubDate>Thu, 12 Feb 2026 13:50:28 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/19-remove-nth-node-from-end-of-list/</guid><description>From naive two-pass traversal to one-pass fast/slow pointers, this ACERS guide explains Remove Nth Node From End of List with correctness intuition, edge cases, engineering mappings, and runnable multi-language code.</description></item><item><title>LeetCode 138: Copy List with Random Pointer — A Complete Deep-Copy Breakdown</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/linked-list/138-copy-list-with-random-pointer/</link><pubDate>Wed, 11 Feb 2026 07:59:32 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/linked-list/138-copy-list-with-random-pointer/</guid><description>The core of copying a random-pointer list is mapping original node identity to copied node identity, then rebuilding next/random pointers. This article uses the ACERS structure to cover intuition, engineering analogies, pitfalls, and runnable multi-language implementations.</description></item><item><title>LeetCode 2: Add Two Numbers from Naive to Optimal Carry Simulation</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2-add-two-numbers/</link><pubDate>Wed, 11 Feb 2026 07:54:26 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2-add-two-numbers/</guid><description>Add two non-negative integers represented by reverse-order linked lists. This ACERS-style guide explains digit-by-digit carry propagation with engineering mappings and runnable multi-language code.</description></item><item><title>Hot100: Sort List Linked-List Merge Sort ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/148-sort-list/</link><pubDate>Tue, 10 Feb 2026 17:07:38 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/148-sort-list/</guid><description>Sort a singly linked list in O(n log n) time using split + recursive merge sort. This guide explains derivation, invariants, engineering mappings, and runnable multi-language implementations.</description></item><item><title>Hot100: Merge K Sorted Lists Divide-and-Conquer O(N log k) ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/23-merge-k-sorted-lists/</link><pubDate>Tue, 10 Feb 2026 17:05:53 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/23-merge-k-sorted-lists/</guid><description>Upgrade from LeetCode 21 to k-way merge: derive why sequential merge degrades, then use divide-and-conquer to reach O(N log k), with heap comparison and runnable multi-language implementations.</description></item><item><title>Hot100: Linked List Cycle II Floyd Detection + Entry Localization ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/142-linked-list-cycle-ii/</link><pubDate>Tue, 10 Feb 2026 10:47:56 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/142-linked-list-cycle-ii/</guid><description>Return the first node where a singly linked list enters a cycle without modifying the list: use Floyd fast/slow pointers to detect a meeting point, then reset one pointer to head and move both one step to localize the entry in O(n) time and O(1) space.</description></item><item><title>Hot100: Merge Two Sorted Lists Sentinel Two-Pointer Merge ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/21-merge-two-sorted-lists/</link><pubDate>Tue, 10 Feb 2026 10:47:02 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/21-merge-two-sorted-lists/</guid><description>Merge two sorted linked lists in O(m+n) with sentinel node and two pointers, with iterative and recursive comparison, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: First Missing Positive In-Place Index Placement ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/41-first-missing-positive/</link><pubDate>Tue, 10 Feb 2026 10:25:53 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/41-first-missing-positive/</guid><description>Find the first missing positive in O(n) time and O(1) extra space using in-place index placement (value x should be placed at index x-1), with engineering mapping, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Reverse Nodes in k-Group Group-Wise In-Place ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/25-reverse-nodes-in-k-group/</link><pubDate>Tue, 10 Feb 2026 10:25:53 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/25-reverse-nodes-in-k-group/</guid><description>Reverse a linked list in groups of k nodes in-place, leaving the last group unchanged if its size is smaller than k. This guide presents a dummy-node + kth-scan + in-place reversal template in O(n) time and O(1) extra space.</description></item><item><title>Hot100: Reorder List In-Place Split-Reverse-Merge ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/143-reorder-list/</link><pubDate>Tue, 10 Feb 2026 09:57:31 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/143-reorder-list/</guid><description>Reorder a linked list to L0-&amp;gt;Ln-&amp;gt;L1-&amp;gt;Ln-1... in O(n) time and O(1) extra space using split, reverse, and alternating merge, with derivation, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Reverse Linked List II Dummy Node + Head-Insertion ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/92-reverse-linked-list-ii/</link><pubDate>Tue, 10 Feb 2026 09:56:14 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/92-reverse-linked-list-ii/</guid><description>Reverse only the interval [left, right] in a singly linked list using a dummy node and in-place head insertion. O(n) time, O(1) extra space, with derivation, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Linked List Cycle Floyd Fast/Slow Pointer ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/141-linked-list-cycle/</link><pubDate>Tue, 10 Feb 2026 08:55:58 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/141-linked-list-cycle/</guid><description>Detect whether a singly linked list has a cycle using Floyd fast/slow pointers in O(n) time and O(1) extra space, with proof intuition, pitfalls, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: Palindrome Linked List Fast/Slow + Reverse Second Half O(1) Space ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/234-palindrome-linked-list/</link><pubDate>Mon, 09 Feb 2026 17:38:32 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/234-palindrome-linked-list/</guid><description>Check whether a singly linked list is a palindrome in O(n) time and O(1) extra space: find middle with fast/slow pointers, reverse second half, compare, then restore list structure.</description></item><item><title>Hot100: Reverse Linked List Three-Pointer Iterative/Recursive ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/206-reverse-linked-list/</link><pubDate>Mon, 09 Feb 2026 17:27:59 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/206-reverse-linked-list/</guid><description>Reverse a singly linked list in O(n) time and O(1) extra space with the three-pointer iterative template, with recursive comparison, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: Subarray Sum Equals K Prefix Sum + Hash Map ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/560-subarray-sum-equals-k/</link><pubDate>Mon, 09 Feb 2026 13:19:45 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/560-subarray-sum-equals-k/</guid><description>Count subarrays whose sum equals k in O(n) using prefix sum and frequency hash map, with engineering scenarios, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Intersection of Two Linked Lists Two-Pointer Switch-Head O(1) Space ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/160-intersection-of-two-linked-lists/</link><pubDate>Mon, 09 Feb 2026 09:26:37 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/160-intersection-of-two-linked-lists/</guid><description>Find the intersection node of two singly linked lists without modifying structure: two pointers switching heads synchronize in O(m+n) time and O(1) extra space, with derivation, engineering mapping, and multi-language implementations.</description></item><item><title>Path Sum III: Prefix Sum + Hash Map Counting Downward Paths (LeetCode 437) ACERS Guide</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/437-path-sum-iii/</link><pubDate>Wed, 04 Feb 2026 16:02:26 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/437-path-sum-iii/</guid><description>Count downward paths in a binary tree whose sum equals targetSum in O(n) using prefix sums and a frequency hash map, with derivation, engineering mapping, and multi-language implementations.</description></item><item><title>Hot100: Spiral Matrix (Boundary Shrinking Simulation ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/54-spiral-matrix/</link><pubDate>Tue, 03 Feb 2026 10:01:50 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/54-spiral-matrix/</guid><description>Traverse a matrix in clockwise spiral order in O(mn) using boundary shrinking. Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>Hot100: Trapping Rain Water (Two Pointers O(n) ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/42-trapping-rain-water/</link><pubDate>Sat, 24 Jan 2026 10:40:53 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/42-trapping-rain-water/</guid><description>Compute trapped rain water in O(n) using two pointers and left/right maxima. Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>Hot100: Maximum Subarray (Kadane O(n) ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/53-maximum-subarray/</link><pubDate>Fri, 23 Jan 2026 13:21:02 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/hot100/53-maximum-subarray/</guid><description>Use Kadane&amp;#39;s algorithm to compute the maximum subarray sum in O(n). Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>LeetCode 1437: Check If All 1's Are at Least K Apart (ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</link><pubDate>Thu, 22 Jan 2026 10:49:42 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</guid><description>One-pass check to ensure all 1s are at least k apart. Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>LeetCode 231: Power of Two (Bit Trick O(1) ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/231-power-of-two/</link><pubDate>Wed, 21 Jan 2026 14:06:56 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/231-power-of-two/</guid><description>Judge whether an integer is a power of two in O(1) time using bit tricks. Includes engineering scenarios, pitfalls, and multi-language solutions.</description></item><item><title>LeetCode 1456: Maximum Number of Vowels in a Substring of Given Length (ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</link><pubDate>Tue, 20 Jan 2026 13:40:45 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</guid><description>Use a fixed-size sliding window to compute the maximum number of vowels in O(n). Includes engineering scenarios and multi-language implementations.</description></item><item><title>LeetCode 239: Sliding Window Maximum (Monotonic Queue ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/239-sliding-window-maximum/</link><pubDate>Mon, 19 Jan 2026 17:46:14 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/239-sliding-window-maximum/</guid><description>Solve Sliding Window Maximum in O(n) with a monotonic queue, including engineering scenarios, complexity comparisons, and multi-language implementations.</description></item><item><title>LeetCode 1512: Number of Good Pairs (Hash Counting ACERS Guide)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1512-number-of-good-pairs/</link><pubDate>Tue, 30 Dec 2025 11:40:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1512-number-of-good-pairs/</guid><description>Solve Good Pairs with one-pass hash counting, plus engineering scenarios, complexity, and multi-language solutions.</description></item><item><title>LeetCode 1: Two Sum (Hash Map ACERS Summary)</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1-two-sum/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/1-two-sum/</guid><description>&lt;h1 id="leetcode-1-two-sum"&gt;LeetCode 1: Two Sum&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Find two indices such that &lt;code&gt;nums[i] + nums[j] = target&lt;/code&gt;. Use a hash map for O(n) time.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Iterate and store &lt;code&gt;value -&amp;gt; index&lt;/code&gt;. For each number &lt;code&gt;x&lt;/code&gt;, check if &lt;code&gt;target - x&lt;/code&gt; exists.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(n)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;two_sum&lt;/span&gt;(nums, target):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; seen &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i, x &lt;span style="color:#f92672"&gt;in&lt;/span&gt; enumerate(nums):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; target &lt;span style="color:#f92672"&gt;-&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; y &lt;span style="color:#f92672"&gt;in&lt;/span&gt; seen:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; [seen[y], i]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; seen[x] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; i
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2300: Successful Pairs of Spells and Potions</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</guid><description>&lt;h1 id="leetcode-2300-successful-pairs-of-spells-and-potions"&gt;LeetCode 2300: Successful Pairs of Spells and Potions&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;For each spell, count how many potions make &lt;code&gt;spell * potion &amp;gt;= success&lt;/code&gt;. Sort potions and binary search the threshold.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Sort potions.&lt;/li&gt;
&lt;li&gt;For each spell, compute &lt;code&gt;need = ceil(success / spell)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use binary search to find the first potion &amp;gt;= need.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n log n)&lt;/li&gt;
&lt;li&gt;Space: O(1) extra (or O(n) if sorting a copy)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; bisect
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; math
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;successful_pairs&lt;/span&gt;(spells, potions, success):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; potions &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sorted(potions)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; n &lt;span style="color:#f92672"&gt;=&lt;/span&gt; len(potions)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; s &lt;span style="color:#f92672"&gt;in&lt;/span&gt; spells:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; need &lt;span style="color:#f92672"&gt;=&lt;/span&gt; (success &lt;span style="color:#f92672"&gt;+&lt;/span&gt; s &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#f92672"&gt;//&lt;/span&gt; s
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; idx &lt;span style="color:#f92672"&gt;=&lt;/span&gt; bisect&lt;span style="color:#f92672"&gt;.&lt;/span&gt;bisect_left(potions, need)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res&lt;span style="color:#f92672"&gt;.&lt;/span&gt;append(n &lt;span style="color:#f92672"&gt;-&lt;/span&gt; idx)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; res
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2379: Minimum Recolors to Get K Consecutive Black Blocks</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</guid><description>&lt;h1 id="leetcode-2379-minimum-recolors-to-get-k-consecutive-black-blocks"&gt;LeetCode 2379: Minimum Recolors to Get K Consecutive Black Blocks&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Given a string of &amp;lsquo;B&amp;rsquo; and &amp;lsquo;W&amp;rsquo;, find the minimum recolors to make a substring of length &lt;code&gt;k&lt;/code&gt; all black.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Use a sliding window of length &lt;code&gt;k&lt;/code&gt; and count the number of whites in the window. The minimum whites across all windows is the answer.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(1)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;minimum_recolors&lt;/span&gt;(blocks, k):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sum(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; c &lt;span style="color:#f92672"&gt;in&lt;/span&gt; blocks[:k] &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; c &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; whites
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i &lt;span style="color:#f92672"&gt;in&lt;/span&gt; range(k, len(blocks)):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; blocks[i&lt;span style="color:#f92672"&gt;-&lt;/span&gt;k] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; blocks[i] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; min(ans, whites)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; ans
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2841: Maximum Sum of Almost Unique Subarray</title><link>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://shio-chan-dev.github.io/jeanblog/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</guid><description>&lt;h1 id="leetcode-2841-maximum-sum-of-almost-unique-subarray"&gt;LeetCode 2841: Maximum Sum of Almost Unique Subarray&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Given an array, window size &lt;code&gt;k&lt;/code&gt;, and threshold &lt;code&gt;m&lt;/code&gt;, find the maximum sum of any length-&lt;code&gt;k&lt;/code&gt; subarray that contains at least &lt;code&gt;m&lt;/code&gt; distinct elements.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Use a sliding window with a frequency map, track window sum and number of distinct values.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(n) for frequency map&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;max_sum_almost_unique&lt;/span&gt;(nums, m, k):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;from&lt;/span&gt; collections &lt;span style="color:#f92672"&gt;import&lt;/span&gt; defaultdict
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count &lt;span style="color:#f92672"&gt;=&lt;/span&gt; defaultdict(int)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i, x &lt;span style="color:#f92672"&gt;in&lt;/span&gt; enumerate(nums):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; count[x] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count[x] &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; i &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; k:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; nums[i &lt;span style="color:#f92672"&gt;-&lt;/span&gt; k]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; y
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count[y] &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; count[y] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; i &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; k &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#f92672"&gt;and&lt;/span&gt; distinct &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; m:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; max(ans, window_sum)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; ans
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>