<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LeetCode on Yosgi</title><link>https://yosgi.github.io/en/tags/leetcode/</link><description>Recent content in LeetCode on Yosgi</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 08 Oct 2026 01:31:25 +0000</lastBuildDate><atom:link href="https://yosgi.github.io/en/tags/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>1104-Binary Tree Pathfinding</title><link>https://yosgi.github.io/en/post/1104-binary-tree-pathfinding/</link><pubDate>Thu, 29 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/1104-binary-tree-pathfinding/</guid><description>Finding the path in a zigzag-labeled binary tree using the symmetry of each level's numbering.</description></item><item><title>Reverse Linked List 2</title><link>https://yosgi.github.io/en/post/reverse-linked-list-2/</link><pubDate>Fri, 23 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/reverse-linked-list-2/</guid><description>Reversing a sublist of a linked list in place using a dummy head and tracking the boundary nodes.</description></item><item><title>1893-Check if all integers in the region are covered</title><link>https://yosgi.github.io/en/post/1893-check-if-all-integers-in-the-region-are-covered/</link><pubDate>Fri, 23 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/1893-check-if-all-integers-in-the-region-are-covered/</guid><description>Checking whether a set of ranges fully covers an interval, from brute force to an interval-compression optimization.</description></item><item><title>138-Copying a linked list with random pointers</title><link>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</link><pubDate>Thu, 22 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/138-copying-a-linked-list-with-random-pointers/</guid><description>Deep-copying a linked list with random pointers using a hash map from old nodes to new.</description></item><item><title>684-Redundant Connection</title><link>https://yosgi.github.io/en/post/684-redundant-connection/</link><pubDate>Wed, 07 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/684-redundant-connection/</guid><description>Detecting the redundant edge that forms a cycle using a union-find template.</description></item><item><title>1202-Swap elements in a string</title><link>https://yosgi.github.io/en/post/1202-swap-elements-in-a-string/</link><pubDate>Tue, 06 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/1202-swap-elements-in-a-string/</guid><description>Producing the lexicographically smallest string after swaps by grouping swappable indices with union-find and sorting each group.</description></item><item><title>778-Swimming in a rising pool</title><link>https://yosgi.github.io/en/post/778-swimming-in-a-rising-pool/</link><pubDate>Mon, 05 Jul 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/778-swimming-in-a-rising-pool/</guid><description>Finding the least time to swim across a rising pool by binary-searching the water level and checking reachability with DFS.</description></item><item><title>475-Heater</title><link>https://yosgi.github.io/en/post/475-heater/</link><pubDate>Thu, 10 Jun 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/475-heater/</guid><description>Finding the minimum heating radius by locating the nearest heater to each house via binary search.</description></item><item><title>875-Keke who loves bananas</title><link>https://yosgi.github.io/en/post/875-keke-who-loves-bananas/</link><pubDate>Wed, 28 Apr 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/875-keke-who-loves-bananas/</guid><description>Finding the minimum banana-eating speed by searching over the range of possible speeds.</description></item><item><title>973-K points closest to the origin</title><link>https://yosgi.github.io/en/post/973-k-points-closest-to-the-origin/</link><pubDate>Sat, 10 Apr 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/973-k-points-closest-to-the-origin/</guid><description>Selecting the K points closest to the origin using a heap.</description></item><item><title>Interview Question-17-14-Minimum Number of K</title><link>https://yosgi.github.io/en/post/interview-question-17-14-minimum-number-of-k/</link><pubDate>Thu, 08 Apr 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/interview-question-17-14-minimum-number-of-k/</guid><description>Finding the smallest K numbers in an array with a heap.</description></item><item><title>347-first-K-high-frequency elements</title><link>https://yosgi.github.io/en/post/347-first-k-high-frequency-elements/</link><pubDate>Thu, 08 Apr 2021 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/347-first-k-high-frequency-elements/</guid><description>Finding the top K most frequent elements by counting occurrences, then selecting with a min-heap.</description></item><item><title>295-Median of data streams</title><link>https://yosgi.github.io/en/post/295-median-of-data-streams/</link><pubDate>Wed, 24 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/295-median-of-data-streams/</guid><description>Maintaining the running median of a data stream with a max-heap and a min-heap.</description></item><item><title>1738-Find the K-th largest XOR coordinate value</title><link>https://yosgi.github.io/en/post/1738-find-the-k-th-largest-xor-coordinate-value/</link><pubDate>Mon, 22 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1738-find-the-k-th-largest-xor-coordinate-value/</guid><description>Finding the k-th largest XOR-coordinate value with a 2D prefix-XOR DP, then selecting the k-th largest.</description></item><item><title>865 - Minimum subtree with all deepest nodes</title><link>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</link><pubDate>Sun, 21 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/865-minimum-subtree-with-all-deepest-nodes/</guid><description>Finding the smallest subtree containing all deepest nodes with a single bottom-up recursion that returns each subtree's depth.</description></item><item><title>1046-The Weight of the Last Stone</title><link>https://yosgi.github.io/en/post/1046-the-weight-of-the-last-stone/</link><pubDate>Sun, 21 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1046-the-weight-of-the-last-stone/</guid><description>Simulating the last stone weight by repeatedly smashing the two heaviest stones with a max-heap.</description></item><item><title>783-Binary Search Tree Node Minimum Distance</title><link>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</link><pubDate>Thu, 18 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/783-binary-search-tree-node-minimum-distance/</guid><description>Finding the minimum distance between BST nodes using the ordered property of in-order traversal.</description></item><item><title>814-Binary Tree Pruning</title><link>https://yosgi.github.io/en/post/814-binary-tree-pruning/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/814-binary-tree-pruning/</guid><description>Pruning subtrees that contain no 1 with post-order traversal, using a dummy parent so the root can also be pruned.</description></item><item><title>1448-Count the number of good nodes in a binary tree</title><link>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1448-count-the-number-of-good-nodes-in-a-binary-tree/</guid><description>Notes on counting good nodes in a binary tree using DFS with a running max.</description></item><item><title>1325-Delete the leaf node of the given value</title><link>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1325-delete-the-leaf-node-of-the-given-value/</guid><description>Post-order traversal approach to delete target-valued leaf nodes using a dummy root.</description></item><item><title>1022 - the sum of the binary numbers from root to leaf</title><link>https://yosgi.github.io/en/post/1022-the-sum-of-the-binary-numbers-from-root-to-leaf/</link><pubDate>Wed, 17 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1022-the-sum-of-the-binary-numbers-from-root-to-leaf/</guid><description>Summing root-to-leaf binary numbers with top-down pre-order traversal.</description></item><item><title>Interview Question-04-12-Sum Path</title><link>https://yosgi.github.io/en/post/interview-question-04-12-sum-path/</link><pubDate>Tue, 16 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/interview-question-04-12-sum-path/</guid><description>Counting paths with a target sum starting from any node, using an outer recursion over nodes and an inner recursion over paths.</description></item><item><title>563-Slope of Binary Tree</title><link>https://yosgi.github.io/en/post/563-slope-of-binary-tree/</link><pubDate>Tue, 16 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/563-slope-of-binary-tree/</guid><description>Computing the total tilt of a binary tree with recursion that returns each subtree's sum.</description></item><item><title>129-Find the sum of numbers from the root node to the leaf node</title><link>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</link><pubDate>Tue, 16 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/129-find-the-sum-of-numbers-from-the-root-node-to-the-leaf-node/</guid><description>Summing all root-to-leaf numbers with top-down pre-order DFS, carrying the running value down each path.</description></item><item><title>124-Maximum Path Sum in a Binary Tree</title><link>https://yosgi.github.io/en/post/124-maximum-path-sum-in-a-binary-tree/</link><pubDate>Mon, 15 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/124-maximum-path-sum-in-a-binary-tree/</guid><description>Finding the maximum path sum in a binary tree with recursion that returns each node's best downward contribution.</description></item><item><title>99-Restore Binary Search Tree</title><link>https://yosgi.github.io/en/post/99-restore-binary-search-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/99-restore-binary-search-tree/</guid><description>Restoring a BST with two swapped nodes by locating them during an in-order traversal.</description></item><item><title>98-Verify Binary Search Tree</title><link>https://yosgi.github.io/en/post/98-verify-binary-search-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/98-verify-binary-search-tree/</guid><description>Validating a binary search tree by exploiting the increasing order of its in-order traversal.</description></item><item><title>863-All nodes with distance -K- in a binary tree</title><link>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/863-all-nodes-with-distance-k-in-a-binary-tree/</guid><description>Finding all nodes at distance K by first adding parent links with DFS, then searching outward from the target.</description></item><item><title>662-Binary Tree Maximum Width</title><link>https://yosgi.github.io/en/post/662-binary-tree-maximum-width/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/662-binary-tree-maximum-width/</guid><description>Computing the maximum width of a binary tree with BFS, tracking each node's position index within its level.</description></item><item><title>222-Number of nodes in a complete binary tree</title><link>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</link><pubDate>Sat, 13 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/222-number-of-nodes-in-a-complete-binary-tree/</guid><description>Counting nodes in a complete binary tree using left/right subtree depths instead of a full DFS.</description></item><item><title>669-Pruning a Binary Search Tree</title><link>https://yosgi.github.io/en/post/669-pruning-a-binary-search-tree/</link><pubDate>Thu, 11 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/669-pruning-a-binary-search-tree/</guid><description>Trimming a BST to a value range by recursing into the correct branch using the BST bounds.</description></item><item><title>450-Delete a node in a binary search tree</title><link>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</link><pubDate>Thu, 11 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/450-delete-a-node-in-a-binary-search-tree/</guid><description>Deleting a node from a binary search tree by locating it via the BST property, then handling the three deletion cases.</description></item><item><title>116-Fill in the next right node pointer of each node</title><link>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</link><pubDate>Wed, 10 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/116-fill-in-the-next-right-node-pointer-of-each-node/</guid><description>Connecting each node to its right neighbor per level, reusing the previous layer's links to reach constant space.</description></item><item><title>1008-Pre-order traversal to construct a binary search tree</title><link>https://yosgi.github.io/en/post/1008-pre-order-traversal-to-construct-a-binary-search-tree/</link><pubDate>Wed, 10 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1008-pre-order-traversal-to-construct-a-binary-search-tree/</guid><description>Constructing a binary search tree from its pre-order sequence by recursively inserting each value.</description></item><item><title>894-All possible full binary trees</title><link>https://yosgi.github.io/en/post/894-all-possible-full-binary-trees/</link><pubDate>Sun, 07 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/894-all-possible-full-binary-trees/</guid><description>Generating all possible full binary trees with recursion that combines left and right subtree counts (DP).</description></item><item><title>297-Serialization and Deserialization of Binary Trees</title><link>https://yosgi.github.io/en/post/297-serialization-and-deserialization-of-binary-trees/</link><pubDate>Thu, 04 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/297-serialization-and-deserialization-of-binary-trees/</guid><description>Serializing a binary tree with BFS and deserializing it using parent/child index relationships.</description></item><item><title>1372-Longest Alternating Path in a Binary Tree</title><link>https://yosgi.github.io/en/post/1372-longest-alternating-path-in-a-binary-tree/</link><pubDate>Mon, 01 Mar 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/1372-longest-alternating-path-in-a-binary-tree/</guid><description>Finding the longest zigzag path in a binary tree with DFS that tracks direction and length, handling the boundary cases.</description></item><item><title>Summary of Binary Trees</title><link>https://yosgi.github.io/en/post/summary-of-binary-trees/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/summary-of-binary-trees/</guid><description>Notes on binary tree traversal — why DFS uses a stack and BFS a queue, with reusable pre/in/post-order and level-order templates.</description></item><item><title>133-Path Sum II</title><link>https://yosgi.github.io/en/post/133-path-sum-ii/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/133-path-sum-ii/</guid><description>Collecting all root-to-leaf paths with a given sum using DFS with backtracking.</description></item><item><title>102 - Level-order Traversal of a Binary Tree</title><link>https://yosgi.github.io/en/post/102-level-order-traversal-of-a-binary-tree/</link><pubDate>Sun, 28 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/102-level-order-traversal-of-a-binary-tree/</guid><description>Techniques and examples for breadth-first (level-order) traversal of binary trees.</description></item><item><title>Two-color labeling</title><link>https://yosgi.github.io/en/post/two-color-labeling/</link><pubDate>Sat, 27 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/two-color-labeling/</guid><description>A GC-inspired color-marking method that unifies iterative pre-, in-, and post-order binary tree traversal under one template.</description></item><item><title>145-Post-order traversal of a binary tree</title><link>https://yosgi.github.io/en/post/145-post-order-traversal-of-a-binary-tree/</link><pubDate>Fri, 26 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/145-post-order-traversal-of-a-binary-tree/</guid><description>Post-order binary tree traversal, both recursively and iteratively with a stack.</description></item><item><title>94-In-order traversal of a binary tree</title><link>https://yosgi.github.io/en/post/94-in-order-traversal-of-a-binary-tree/</link><pubDate>Thu, 25 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/94-in-order-traversal-of-a-binary-tree/</guid><description>In-order binary tree traversal, both recursively and iteratively with an explicit stack.</description></item><item><title>215. Kth Largest Element in an Array</title><link>https://yosgi.github.io/en/post/215-kth-largest-element-in-an-array/</link><pubDate>Thu, 25 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/215-kth-largest-element-in-an-array/</guid><description>Finding the k-th largest element with quickselect, an optimized partition-based quicksort.</description></item><item><title>144-Pre-order traversal of a binary tree</title><link>https://yosgi.github.io/en/post/144-pre-order-traversal-of-a-binary-tree/</link><pubDate>Thu, 25 Feb 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/144-pre-order-traversal-of-a-binary-tree/</guid><description>Iterative pre-order binary tree traversal using an explicit stack.</description></item><item><title>105-Constructing a binary tree from pre-order and in-order traversal sequences-1</title><link>https://yosgi.github.io/en/post/105-constructing-a-binary-tree-from-pre-order-and-in-order-traversal-sequences-1/</link><pubDate>Wed, 27 Jan 2021 00:00:00 +1300</pubDate><guid>https://yosgi.github.io/en/post/105-constructing-a-binary-tree-from-pre-order-and-in-order-traversal-sequences-1/</guid><description>Reconstructing a binary tree from its pre-order and in-order sequences by recursively splitting on the root.</description></item><item><title>Arrays, stacks, queues</title><link>https://yosgi.github.io/en/post/arrays-stacks-queues/</link><pubDate>Wed, 22 Aug 2018 15:09:45 +1200</pubDate><guid>https://yosgi.github.io/en/post/arrays-stacks-queues/</guid><description>Javascript Data Structures</description></item><item><title>Javascript sorting algorithm</title><link>https://yosgi.github.io/en/post/javascript-sorting-algorithm/</link><pubDate>Mon, 25 Jun 2018 18:48:42 +1200</pubDate><guid>https://yosgi.github.io/en/post/javascript-sorting-algorithm/</guid><description>Javascript algorithm sorting algorithm</description></item><item><title>Set and Map Data Structures</title><link>https://yosgi.github.io/en/post/set-and-map-data-structures/</link><pubDate>Wed, 02 May 2018 00:00:00 +1200</pubDate><guid>https://yosgi.github.io/en/post/set-and-map-data-structures/</guid><description>"ES6 Standard Introduction" Knowledge Points Summary</description></item></channel></rss>