From 033d4e9b6dddb676f0a4b4f836805c7626f8ff3b Mon Sep 17 00:00:00 2001 From: dohee Date: Sat, 7 Feb 2026 16:30:20 -0500 Subject: [PATCH 01/10] Week 13 Kth Smallest Element in a BST Solution --- kth-smallest-element-in-a-bst/doh6077.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 kth-smallest-element-in-a-bst/doh6077.py diff --git a/kth-smallest-element-in-a-bst/doh6077.py b/kth-smallest-element-in-a-bst/doh6077.py new file mode 100644 index 000000000..a474798fb --- /dev/null +++ b/kth-smallest-element-in-a-bst/doh6077.py @@ -0,0 +1,27 @@ +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + # Time Complexity O(N) + def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: + ans = [] + final = [0] + + def dfs(node): + + if not node: + return + + dfs(node.left) + + ans.append(node.val) + if len(ans) == k: + final[0] = node.val + if len(ans) < k: + dfs(node.right) + dfs(root) + return final[0] + \ No newline at end of file From 135d9810b0fe226a05a8dcaca1e570bff3d01ac4 Mon Sep 17 00:00:00 2001 From: dohee Date: Sun, 8 Feb 2026 13:14:23 -0500 Subject: [PATCH 02/10] Week 14: 102. Binary Tree Level Order Traversal Solution --- binary-tree-level-order-traversal/doh6077.py | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 binary-tree-level-order-traversal/doh6077.py diff --git a/binary-tree-level-order-traversal/doh6077.py b/binary-tree-level-order-traversal/doh6077.py new file mode 100644 index 000000000..9ec221786 --- /dev/null +++ b/binary-tree-level-order-traversal/doh6077.py @@ -0,0 +1,30 @@ +from collections import deque +# 102. Binary Tree Level Order Traversal +class Solution: + def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: + # 1. Edge Case: Empty Tree + if not root: + return [] + + result = [] + queue = deque([root]) + + while queue: + # 2. Capture the number of nodes at the current level + level_size = len(queue) + current_level_nodes = [] + + for _ in range(level_size): + current_node = queue.popleft() + current_level_nodes.append(current_node.val) + + # 3. Add children to the queue for the NEXT level + if current_node.left: + queue.append(current_node.left) + if current_node.right: + queue.append(current_node.right) + + # Add the finished level to our result + result.append(current_level_nodes) + + return result \ No newline at end of file From 2d3019a4f2cfe41cf135179b1a6b25bf62e6e7c0 Mon Sep 17 00:00:00 2001 From: dohee Date: Mon, 9 Feb 2026 13:49:15 -0500 Subject: [PATCH 03/10] Week1 House Robber solution --- house-robber/doh6077.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 house-robber/doh6077.py diff --git a/house-robber/doh6077.py b/house-robber/doh6077.py new file mode 100644 index 000000000..0d3e32e1f --- /dev/null +++ b/house-robber/doh6077.py @@ -0,0 +1,30 @@ +# Week1 +# 198. House Robber +# Tabulation +# Dynamic Programming + + +# two options: either rober or not + +class Solution: + def rob(self, nums: List[int]) -> int: + # Top Down DP + + n = len(nums) + + if n ==1: + return nums[0] + if n ==2: + return max(nums[0], nums[1]) + memo = {0:nums[0], 1: max(nums[0], nums[1])} + def helper(i): + + if i in memo: + return memo[i] + else: + memo[i]= max(nums[i] + helper(i-2), helper(i-1)) + return memo[i] + + return helper(n-1) + + \ No newline at end of file From 604bb505a44f8d19d306bef8358303b53fdb6bce Mon Sep 17 00:00:00 2001 From: dohee Date: Mon, 16 Feb 2026 12:11:38 -0500 Subject: [PATCH 04/10] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binary-tree-level-order-traversal/doh6077.py | 2 +- house-robber/doh6077.py | 2 -- kth-smallest-element-in-a-bst/doh6077.py | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/binary-tree-level-order-traversal/doh6077.py b/binary-tree-level-order-traversal/doh6077.py index 9ec221786..83ad4c833 100644 --- a/binary-tree-level-order-traversal/doh6077.py +++ b/binary-tree-level-order-traversal/doh6077.py @@ -27,4 +27,4 @@ def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]: # Add the finished level to our result result.append(current_level_nodes) - return result \ No newline at end of file + return result diff --git a/house-robber/doh6077.py b/house-robber/doh6077.py index 0d3e32e1f..c4ce97e59 100644 --- a/house-robber/doh6077.py +++ b/house-robber/doh6077.py @@ -26,5 +26,3 @@ def helper(i): return memo[i] return helper(n-1) - - \ No newline at end of file diff --git a/kth-smallest-element-in-a-bst/doh6077.py b/kth-smallest-element-in-a-bst/doh6077.py index a474798fb..b5495ed01 100644 --- a/kth-smallest-element-in-a-bst/doh6077.py +++ b/kth-smallest-element-in-a-bst/doh6077.py @@ -24,4 +24,3 @@ def dfs(node): dfs(node.right) dfs(root) return final[0] - \ No newline at end of file From 146fb43b720359a05df1f78bb1480117c222510d Mon Sep 17 00:00:00 2001 From: dohee Date: Mon, 16 Feb 2026 12:43:50 -0500 Subject: [PATCH 05/10] Week 15: 572. Subtree of Another Tree Solution --- subtree-of-another-tree/doh6077.py | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 subtree-of-another-tree/doh6077.py diff --git a/subtree-of-another-tree/doh6077.py b/subtree-of-another-tree/doh6077.py new file mode 100644 index 000000000..da4226573 --- /dev/null +++ b/subtree-of-another-tree/doh6077.py @@ -0,0 +1,43 @@ +from collections import deque +from typing import Optional + +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +# 572. Subtree of Another Tree +# https://leetcode.com/problems/subtree-of-another-tree/description/ +class Solution: + def isSubtree(self, root: Optional[TreeNode], subRoot: Optional[TreeNode]) -> bool: + # Use BFS => Queue + # Edge cases + if subRoot is None: + return True + if root is None: + return False + + def helper(node: Optional[TreeNode], subNode: Optional[TreeNode]) -> bool: + if node is None and subNode is None: + return True + if node is None or subNode is None: + return False + if node.val != subNode.val: + return False + return helper(node.left, subNode.left) and helper(node.right, subNode.right) + + q = deque([root]) + + while q: + curr = q.popleft() + + # Only attempt full compare when root values match + if curr.val == subRoot.val and helper(curr, subRoot): + return True + + if curr.left: + q.append(curr.left) + if curr.right: + q.append(curr.right) + + return False From 92a88128670dca2d07721dec2b9ffd3e1d8442f6 Mon Sep 17 00:00:00 2001 From: Dohee Kim <134092191+doh6077@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:03:31 -0500 Subject: [PATCH 06/10] Apply suggestion from @DaleSeo Co-authored-by: Dale Seo <5466341+DaleSeo@users.noreply.github.com> --- house-robber/doh6077.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/house-robber/doh6077.py b/house-robber/doh6077.py index c4ce97e59..38c59e588 100644 --- a/house-robber/doh6077.py +++ b/house-robber/doh6077.py @@ -12,9 +12,9 @@ def rob(self, nums: List[int]) -> int: n = len(nums) - if n ==1: + if n == 1: return nums[0] - if n ==2: + if n == 2: return max(nums[0], nums[1]) memo = {0:nums[0], 1: max(nums[0], nums[1])} def helper(i): From 24ba0c6b3f0e131a44eed1e4675c6f61b6557aff Mon Sep 17 00:00:00 2001 From: Dohee Kim <134092191+doh6077@users.noreply.github.com> Date: Wed, 18 Feb 2026 17:06:21 -0500 Subject: [PATCH 07/10] Apply suggestion from @DaleSeo Co-authored-by: Dale Seo <5466341+DaleSeo@users.noreply.github.com> --- house-robber/doh6077.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/house-robber/doh6077.py b/house-robber/doh6077.py index 38c59e588..b980c6f86 100644 --- a/house-robber/doh6077.py +++ b/house-robber/doh6077.py @@ -16,7 +16,7 @@ def rob(self, nums: List[int]) -> int: return nums[0] if n == 2: return max(nums[0], nums[1]) - memo = {0:nums[0], 1: max(nums[0], nums[1])} + memo = {0: nums[0], 1: max(nums[0], nums[1])} def helper(i): if i in memo: From 342f8d86160a93e60add1dc6a0694973813eb74e Mon Sep 17 00:00:00 2001 From: dohee Date: Wed, 18 Feb 2026 17:20:20 -0500 Subject: [PATCH 08/10] Refactor kthSmallest to use the nonlocal keyword for tracking the result --- kth-smallest-element-in-a-bst/doh6077.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/kth-smallest-element-in-a-bst/doh6077.py b/kth-smallest-element-in-a-bst/doh6077.py index b5495ed01..d053cf5af 100644 --- a/kth-smallest-element-in-a-bst/doh6077.py +++ b/kth-smallest-element-in-a-bst/doh6077.py @@ -8,19 +8,16 @@ class Solution: # Time Complexity O(N) def kthSmallest(self, root: Optional[TreeNode], k: int) -> int: ans = [] - final = [0] - + final = 0 def dfs(node): - + nonlocal final if not node: return - dfs(node.left) - ans.append(node.val) if len(ans) == k: - final[0] = node.val + final = node.val if len(ans) < k: dfs(node.right) dfs(root) - return final[0] + return final From 52dfd631618ea32e02227fbd3e02c64927058bae Mon Sep 17 00:00:00 2001 From: dohee Date: Wed, 18 Feb 2026 18:09:46 -0500 Subject: [PATCH 09/10] Week 15: Rotate Image Solution --- rotate-image/doh6077.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 rotate-image/doh6077.py diff --git a/rotate-image/doh6077.py b/rotate-image/doh6077.py new file mode 100644 index 000000000..901ee8c81 --- /dev/null +++ b/rotate-image/doh6077.py @@ -0,0 +1,29 @@ +# https://leetcode.com/problems/rotate-image/ +# 48. Rotate Image +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + # First Try - Thought process: + # group values by column index (j) to rebuild rows + # Brute force: create an extra 2D matrix and then copy it back into matrix + # Needs optimization: this approach uses extra space + matrix_result = [[] for _ in range(len(matrix))] + for i in reversed(matrix): + for j, value in enumerate(i): + matrix_result[j].append(value) + for r in range(len(matrix)): + matrix[r] = matrix_result[r] + + # Youtube Solution - Transpose Operation + hr + # Swap i, js + n = len(matrix) + for i in range(n): + for j in range(i + 1, n): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + + # Reflection + for i in range(n): + for j in range(n // 2): + matrix[i][j], matrix[i][n - j - 1] = matrix[i][n - j - 1], matrix[i][j] From 04fcf317b43f43eb36d832ffb18d39cac8d0848c Mon Sep 17 00:00:00 2001 From: dohee Date: Fri, 20 Feb 2026 12:39:31 -0500 Subject: [PATCH 10/10] Week 15: 5. Longest Palindromic Substring Solution --- longest-palindromic-substring/doh6077.py | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 longest-palindromic-substring/doh6077.py diff --git a/longest-palindromic-substring/doh6077.py b/longest-palindromic-substring/doh6077.py new file mode 100644 index 000000000..c60f534d9 --- /dev/null +++ b/longest-palindromic-substring/doh6077.py @@ -0,0 +1,30 @@ +# 5. Longest Palindromic Substring +# https://leetcode.com/problems/longest-palindromic-substring/ + + +class Solution: + def longestPalindrome(self, s: str) -> str: + #Expand Around Center + res = "" + resLen = 0 + + for i in range(len(s)): + # odd length + l, r = i, i + while l >= 0 and r < len(s) and s[l] == s[r]: + if (r - l + 1) > resLen: + res = s[l:r+1] + resLen = r - l + 1 + l -= 1 + r += 1 + + # even length + l, r = i, i + 1 + while l >= 0 and r < len(s) and s[l] == s[r]: + if (r - l + 1) > resLen: + res = s[l:r+1] + resLen = r - l + 1 + l -= 1 + r += 1 + + return res